Browse Source

Add additional `data:path` events

add-css-mount-events
Artur Arseniev 8 months ago
parent
commit
e5fbd64036
  1. 10
      packages/core/src/data_sources/model/DataRecord.ts

10
packages/core/src/data_sources/model/DataRecord.ts

@ -63,9 +63,9 @@ export default class DataRecord<T extends DataRecordProps = DataRecordProps> ext
* @private * @private
* @name handleChange * @name handleChange
*/ */
handleChange() { handleChange(m: DataRecord, opts: SetOptions) {
const changed = this.changedAttributes(); const changed = this.changedAttributes();
keys(changed).forEach((prop) => this.triggerChange(prop)); keys(changed).forEach((prop) => this.triggerChange(prop, opts));
} }
/** /**
@ -113,10 +113,12 @@ export default class DataRecord<T extends DataRecordProps = DataRecordProps> ext
* @param {String} [prop] - Optional property name to trigger a change event for a specific property. * @param {String} [prop] - Optional property name to trigger a change event for a specific property.
* @name triggerChange * @name triggerChange
*/ */
triggerChange(prop?: string) { triggerChange(prop?: string, options: SetOptions = {}) {
const { dataSource, em } = this; const { dataSource, em } = this;
const data = { dataSource, dataRecord: this };
const paths = this.getPaths(prop); const paths = this.getPaths(prop);
const data = { dataSource, dataRecord: this, path: paths[0], options };
em.trigger(DataSourcesEvents.path, data);
em.trigger(`${DataSourcesEvents.path}:${dataSource.id}`, data);
paths.forEach((path) => em.trigger(`${DataSourcesEvents.path}:${path}`, { ...data, path })); paths.forEach((path) => em.trigger(`${DataSourcesEvents.path}:${path}`, { ...data, path }));
} }

Loading…
Cancel
Save