Skip to content

Commit c401aac

Browse files
edgarmuellerlucas-koehler
authored andcommitted
Introduce config object and fix linter warnings
1 parent 82556d3 commit c401aac

File tree

6 files changed

+242
-245
lines changed

6 files changed

+242
-245
lines changed

src/core.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ export interface JsonFormService {
1919
dispose(): void;
2020
}
2121

22+
export class JsonFormsConfig {
23+
24+
private _identifyingProp;
25+
26+
setIdentifyingProp(propName: string) {
27+
this._identifyingProp = propName;
28+
}
29+
30+
getIdentifyingProp() {
31+
return this._identifyingProp;
32+
}
33+
34+
shouldGenerateIdentifier() {
35+
return this._identifyingProp !== undefined;
36+
}
37+
}
38+
2239
/**
2340
* Encapsulates instantiation logic of a JSONForms service.
2441
*/
@@ -37,6 +54,7 @@ export interface JsonFormsServiceConstructable {
3754
* Global JSONForms object that holds services and registries.
3855
*/
3956
export class JsonForms {
57+
private static _config = new JsonFormsConfig();
4058
private static _schemaService;
4159
public static rendererService = new RendererService();
4260
public static jsonFormsServices: JsonFormsServiceConstructable[] = [];
@@ -54,6 +72,10 @@ export class JsonForms {
5472
return this._schemaService;
5573
}
5674

75+
public static get config(): JsonFormsConfig {
76+
return this._config;
77+
}
78+
5779
/**
5880
* Uses the model mapping to filter all objects that are associated with the type
5981
* defined by the given schema id. If there is no applicable mapping,

src/core/schema.service.impl.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SchemaService
1010
} from './schema.service';
1111
import * as uuid from 'uuid';
12+
import { JsonForms } from '../core';
1213

1314
interface ReferenceSchemaMap {
1415
[ref: string]: JsonSchema;
@@ -139,7 +140,6 @@ const getReference = (href: string, variable: string, variableWrapped: string) =
139140
};
140141

141142
export class SchemaServiceImpl implements SchemaService {
142-
private _identifyingProp;
143143
private selfContainedSchemas: {[id: string]: JsonSchema} = {};
144144
constructor(private rootSchema: JsonSchema) {
145145
if (_.isEmpty(rootSchema.id)) {
@@ -194,7 +194,7 @@ export class SchemaServiceImpl implements SchemaService {
194194
variable,
195195
variable,
196196
pathToContainment.substring(0, pathToContainment.length - 1),
197-
this._identifyingProp,
197+
JsonForms.config.getIdentifyingProp(),
198198
addReference(schema, variable, pathToContainment),
199199
getReference(href, variable, variableWrapped)
200200
)
@@ -210,25 +210,6 @@ export class SchemaServiceImpl implements SchemaService {
210210
return [];
211211
}
212212

213-
/**
214-
* @inheritDoc
215-
*/
216-
setIdentifyingProp(propName: string): SchemaService {
217-
this._identifyingProp = propName;
218-
219-
return this;
220-
}
221-
222-
/**
223-
* Determines whether the identifigenerer value should be generated
224-
* @returns {boolean} true, if the the identifying value should be generated
225-
*
226-
* @see setIdentifyingProp
227-
*/
228-
shouldGenerateIdentifier() {
229-
return this._identifyingProp !== undefined;
230-
}
231-
232213
private getContainment(key: string, name: string, schema: JsonSchema, rootSchema: JsonSchema,
233214
isInContainment: boolean,
234215
addFunction: (data: object) => (valueToAdd: object,
@@ -276,7 +257,7 @@ export class SchemaServiceImpl implements SchemaService {
276257
schema.items,
277258
rootSchema,
278259
true,
279-
addToArray(key, this._identifyingProp),
260+
addToArray(key, JsonForms.config.getIdentifyingProp()),
280261
deleteFromArray(key),
281262
getArray(key)
282263
);

src/core/schema.service.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,4 @@ export interface SchemaService {
245245
* @see ReferenceProperty
246246
*/
247247
getReferenceProperties(schema: JsonSchema): ReferenceProperty[];
248-
249-
/**
250-
* Set the name of the property that uniquely identifies any given schema element.
251-
*
252-
* @param propName the name of the identifying property
253-
* @return the schema service itself for convenience reasons
254-
*/
255-
setIdentifyingProp(propName: string): SchemaService;
256248
}

0 commit comments

Comments
 (0)