@travetto/schema
Advanced tools
Comparing version 0.0.23 to 0.0.24
@@ -28,3 +28,3 @@ { | ||
}, | ||
"version": "0.0.23" | ||
"version": "0.0.24" | ||
} |
@@ -128,43 +128,43 @@ import { ClassList, FieldConfig, ClassConfig, ViewConfig } from './types'; | ||
onFieldChange<T>(callback: (e: ChangeEvent<FieldConfig>) => any): void { | ||
this.events.on('field:change', callback); | ||
} | ||
emitFieldDelta(cls: Class) { | ||
const prev = this.getExpired(cls); | ||
const curr = this.get(cls); | ||
emitFieldChange(ev: ChangeEvent<FieldConfig>) { | ||
this.events.emit('field:change', ev); | ||
} | ||
const prevView = prev.views[this.DEFAULT_VIEW]; | ||
const currView = curr.views[this.DEFAULT_VIEW]; | ||
computeFieldDelta(cls: Class) { | ||
const previous = this.getExpired(cls); | ||
const current = this.get(cls); | ||
if (previous && current) { | ||
const prevView = previous.views[this.DEFAULT_VIEW]; | ||
const currView = current.views[this.DEFAULT_VIEW]; | ||
const prevFields = new Set(prevView.fields); | ||
const currFields = new Set(currView.fields); | ||
const prevFields = new Set(prevView.fields); | ||
const currFields = new Set(currView.fields); | ||
for (const c of currFields) { | ||
if (!prevFields.has(c)) { | ||
this.emitFieldChange({ curr: currView.schema[c], type: 'added' }); | ||
} | ||
const changes: ChangeEvent<FieldConfig>[] = []; | ||
for (const c of currFields) { | ||
if (!prevFields.has(c)) { | ||
changes.push({ curr: currView.schema[c], type: 'added' }); | ||
} | ||
} | ||
for (const c of prevFields) { | ||
if (!currFields.has(c)) { | ||
this.emitFieldChange({ prev: prevView.schema[c], type: 'removing' }); | ||
} | ||
for (const c of prevFields) { | ||
if (!currFields.has(c)) { | ||
changes.push({ prev: prevView.schema[c], type: 'removing' }); | ||
} | ||
} | ||
for (const c of currFields) { | ||
if (prevFields.has(c)) { | ||
const { type, ...prevSchema } = prevView.schema[c]; | ||
const { type: type2, ...currSchema } = currView.schema[c]; | ||
if (JSON.stringify(prevSchema) !== JSON.stringify(currSchema)) { | ||
this.emitFieldChange({ prev: prevView.schema[c], curr: currView.schema[c], type: 'changed' }); | ||
} | ||
for (const c of currFields) { | ||
if (prevFields.has(c)) { | ||
const { type, ...prevSchema } = prevView.schema[c]; | ||
const { type: type2, ...currSchema } = currView.schema[c]; | ||
if (JSON.stringify(prevSchema) !== JSON.stringify(currSchema)) { | ||
changes.push({ prev: prevView.schema[c], curr: currView.schema[c], type: 'changed' }); | ||
} | ||
} | ||
} | ||
this.events.emit('field:change', { cls, changes }); | ||
} | ||
onFieldChange<T>(callback: (e: { cls: Class, changes: ChangeEvent<FieldConfig>[] }) => any): void { | ||
this.events.on('field:change', callback); | ||
} | ||
onInstallFinalize(cls: Class) { | ||
@@ -189,8 +189,13 @@ | ||
this.computeFieldDelta(cls); | ||
return config; | ||
} | ||
emit(ev: ChangeEvent<Class>) { | ||
super.emit(ev); | ||
if (ev.type === 'changed') { | ||
this.emitFieldDelta(ev.curr!); | ||
} | ||
} | ||
} | ||
export const SchemaRegistry = new $SchemaRegistry(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43849
28
1260