Skip to content

Commit

Permalink
fix(core): Handle multiple ajsf #213
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzahamidi committed Oct 31, 2021
1 parent 205f3cd commit 7e6d394
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "demo",
"version": "13.1.1",
"version": "13.1.2",
"author": "https://github.com/hamzahamidi/Angular6-json-schema-form/graphs/contributors",
"description": "Angular JSON Schema Form builder Demo",
"engines": {
Expand Down Expand Up @@ -55,7 +55,7 @@
"ng": "ng",
"prestart": "npm run build:libs",
"start": "ng serve",
"start:prod": "ng serve --configuration production",
"start:demo-only": "ng serve",
"build:core": "ng build @ajsf/core --configuration production",
"postbuild:core": "cp README.md LICENSE dist/@ajsf/core/",
"build:bs3": "ng build @ajsf/bootstrap3 --configuration production",
Expand Down
4 changes: 2 additions & 2 deletions projects/ajsf-bootstrap3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ajsf/bootstrap3",
"version": "0.5.1-beta.2",
"version": "0.5.1-beta.3",
"description": "Angular JSON Schema Form builder using Bootstrap 3 UI",
"author": "https://github.com/hamzahamidi/ajsf/graphs/contributors",
"keywords": [
Expand Down Expand Up @@ -29,7 +29,7 @@
"private": false,
"dependencies": {
"lodash-es": "~4.17.21",
"@ajsf/core": "~0.5.1-beta.2",
"@ajsf/core": "~0.5.1-beta.3",
"tslib": "^2.0.0"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { CommonModule } from '@angular/common';
import {
JsonSchemaFormModule,
JsonSchemaFormService,
WidgetLibraryModule
} from '@ajsf/core';
import { Bootstrap3FrameworkComponent } from './bootstrap3-framework.component';
Expand All @@ -17,7 +18,8 @@ describe('Bootstrap3FrameworkComponent', () => {
CommonModule,
WidgetLibraryModule,
],
declarations: [Bootstrap3FrameworkComponent]
declarations: [Bootstrap3FrameworkComponent],
providers: [JsonSchemaFormService]
})
.compileComponents();
}));
Expand Down
4 changes: 2 additions & 2 deletions projects/ajsf-bootstrap4/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ajsf/bootstrap4",
"version": "0.5.1-beta.2",
"version": "0.5.1-beta.3",
"description": "Angular JSON Schema Form builder using Bootstrap 4 UI",
"author": "https://github.com/hamzahamidi/ajsf/graphs/contributors",
"keywords": [
Expand Down Expand Up @@ -29,7 +29,7 @@
"private": false,
"dependencies": {
"lodash-es": "~4.17.21",
"@ajsf/core": "~0.5.1-beta.2",
"@ajsf/core": "~0.5.1-beta.3",
"tslib": "^2.0.0"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { CommonModule } from '@angular/common';
import {
JsonSchemaFormModule,
JsonSchemaFormService,
WidgetLibraryModule
} from '@ajsf/core';
import { Bootstrap4FrameworkComponent } from './bootstrap4-framework.component';
Expand All @@ -17,7 +18,8 @@ describe('FwBootstrap4Component', () => {
CommonModule,
WidgetLibraryModule,
],
declarations: [Bootstrap4FrameworkComponent]
declarations: [Bootstrap4FrameworkComponent],
providers: [JsonSchemaFormService]
})
.compileComponents();
}));
Expand Down
2 changes: 1 addition & 1 deletion projects/ajsf-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ajsf/core",
"version": "0.5.1-beta.2",
"version": "0.5.1-beta.3",
"description": "Angular JSON Schema Form builder core",
"author": "https://github.com/hamzahamidi/ajsf/graphs/contributors",
"keywords": [
Expand Down
13 changes: 11 additions & 2 deletions projects/ajsf-core/src/lib/json-schema-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {
ChangeDetectorRef,
Component,
EventEmitter,
forwardRef,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges,
} from '@angular/core';
import { ControlValueAccessor } from '@angular/forms';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { convertSchemaToDraft6 } from './shared/convert-schema-to-draft6.function';
import { forEach, hasOwn } from './shared/utility.functions';
import { FrameworkLibraryService } from './framework-library/framework-library.service';
Expand All @@ -28,6 +29,11 @@ import { JsonSchemaFormService } from './json-schema-form.service';
import { resolveSchemaReferences } from './shared/json-schema.functions';
import { WidgetLibraryService } from './widget-library/widget-library.service';

export const JSON_SCHEMA_FORM_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => JsonSchemaFormComponent),
multi: true,
};

/**
* @module 'JsonSchemaFormComponent' - Angular JSON Schema Form
Expand Down Expand Up @@ -67,7 +73,10 @@ import { WidgetLibraryService } from './widget-library/widget-library.service';
// tslint:disable-next-line:component-selector
selector: 'json-schema-form',
templateUrl: './json-schema-form.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
changeDetection: ChangeDetectionStrategy.OnPush,
// Adding 'JsonSchemaFormService' here, instead of in the module,
// creates a separate instance of the service for each component
providers: [ JsonSchemaFormService, JSON_SCHEMA_FORM_VALUE_ACCESSOR ],
})
export class JsonSchemaFormComponent implements ControlValueAccessor, OnChanges, OnInit {
debugOutput: any; // Debug information, if requested
Expand Down
4 changes: 1 addition & 3 deletions projects/ajsf-core/src/lib/json-schema-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ export interface ErrorMessages {
}[];
}

@Injectable({
providedIn: 'root',
})
@Injectable()
export class JsonSchemaFormService {
JsonFormCompatibility = false;
ReactJsonSchemaFormCompatibility = false;
Expand Down
4 changes: 2 additions & 2 deletions projects/ajsf-material/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ajsf/material",
"version": "0.5.1-beta.2",
"version": "0.5.1-beta.3",
"description": "Angular JSON Schema Form builder using Angular Material UI",
"author": "https://github.com/hamzahamidi/ajsf/graphs/contributors",
"keywords": [
Expand Down Expand Up @@ -29,7 +29,7 @@
"private": false,
"dependencies": {
"lodash-es": "~4.17.21",
"@ajsf/core": "~0.5.1-beta.2",
"@ajsf/core": "~0.5.1-beta.3",
"tslib": "^2.0.0"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { CommonModule } from '@angular/common';
import {
JsonSchemaFormModule,
JsonSchemaFormService,
WidgetLibraryModule
} from '@ajsf/core';
import { MaterialDesignFrameworkComponent } from './material-design-framework.component';
Expand All @@ -17,7 +18,8 @@ describe('FwBootstrap4Component', () => {
CommonModule,
WidgetLibraryModule,
],
declarations: [MaterialDesignFrameworkComponent]
declarations: [MaterialDesignFrameworkComponent],
providers: [JsonSchemaFormService]
})
.compileComponents();
}));
Expand Down

0 comments on commit 7e6d394

Please sign in to comment.