|
|
@ -1,12 +1,15 @@ |
|
|
import { DataSourcesEvents } from '../../dataSources/types'; |
|
|
import { DataSourcesEvents, DataVariableListener } from '../../dataSources/types'; |
|
|
import { stringToPath } from '../../utils/mixins'; |
|
|
import { stringToPath } from '../../utils/mixins'; |
|
|
import ComponentDataVariable from '../model/ComponentDataVariable'; |
|
|
import ComponentDataVariable from '../model/ComponentDataVariable'; |
|
|
import ComponentView from './ComponentView'; |
|
|
import ComponentView from './ComponentView'; |
|
|
|
|
|
|
|
|
export default class ComponentDataVariableView extends ComponentView<ComponentDataVariable> { |
|
|
export default class ComponentDataVariableView extends ComponentView<ComponentDataVariable> { |
|
|
|
|
|
dataListeners: DataVariableListener[] = []; |
|
|
|
|
|
|
|
|
initialize(opt = {}) { |
|
|
initialize(opt = {}) { |
|
|
super.initialize(opt); |
|
|
super.initialize(opt); |
|
|
this.listenToData(); |
|
|
this.listenToData(); |
|
|
|
|
|
this.listenTo(this.model, 'change:path', this.listenToData); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
listenToData() { |
|
|
listenToData() { |
|
|
@ -15,16 +18,21 @@ export default class ComponentDataVariableView extends ComponentView<ComponentDa |
|
|
const normPath = stringToPath(path || '').join('.'); |
|
|
const normPath = stringToPath(path || '').join('.'); |
|
|
const { DataSources } = em; |
|
|
const { DataSources } = em; |
|
|
const [ds, dr] = DataSources.fromPath(path); |
|
|
const [ds, dr] = DataSources.fromPath(path); |
|
|
|
|
|
const dataListeners: DataVariableListener[] = []; |
|
|
|
|
|
const prevListeners = this.dataListeners || []; |
|
|
|
|
|
|
|
|
|
|
|
prevListeners.forEach(ls => this.stopListening(ls.obj, ls.event, this.postRender)); |
|
|
|
|
|
|
|
|
if (ds) { |
|
|
ds && dataListeners.push({ obj: ds.records, event: 'add remove reset' }); |
|
|
this.listenTo(ds.records, 'add remove reset', this.postRender); |
|
|
dr && dataListeners.push({ obj: dr, event: 'change' }); |
|
|
this.listenTo(ds.records, 'add remove reset', this.postRender); |
|
|
dataListeners.push( |
|
|
dr && this.listenTo(dr, 'change', this.postRender); |
|
|
{ obj: model, event: 'change:path change:value' }, |
|
|
} |
|
|
{ obj: DataSources.all, event: 'add remove reset' }, |
|
|
|
|
|
{ obj: em, event: `${DataSourcesEvents.path}:${normPath}` } |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
this.listenTo(DataSources.all, 'add remove reset', this.postRender); |
|
|
dataListeners.forEach(ls => this.listenTo(ls.obj, ls.event, this.postRender)); |
|
|
this.listenTo(em, `${DataSourcesEvents.path}:${normPath}`, this.postRender); |
|
|
this.dataListeners = dataListeners; |
|
|
this.listenTo(model, 'change:path change:value', this.postRender); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
postRender() { |
|
|
postRender() { |
|
|
|