Skip to content

Commit de4b555

Browse files
committed
fix(ModelManager): Create data model and run hooks on view add
1 parent 4f6d1e7 commit de4b555

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/core/ModelManager.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ export default class ModelManager {
143143
viewList.push({ name, id: this.nextViewId++ });
144144
this.data = assignObjKey(this.data, viewName, viewList);
145145
this.activateView(viewName, index);
146+
// generate data model for new view (...using a get method with side-effects...)
147+
this.getPropertyList();
148+
this.runHooks();
149+
this.invokeListeners();
146150
}
147151

148152
// --------
@@ -184,17 +188,26 @@ export default class ModelManager {
184188
newData.value
185189
);
186190

187-
const hooks = this.model.views[this.activeViewName].hooks || [];
188-
hooks.forEach((hook) =>
189-
HookManager.applyHook(hook, this.fullData, viewData, this.model)
190-
);
191-
191+
this.runHooks();
192192
this.invokeListeners();
193193
}
194194
}
195195

196196
// --------
197197

198+
runHooks(viewName = null, viewIndex = null) {
199+
const name = viewName || this.activeViewName;
200+
const index = viewIndex || this.activeViewIndex;
201+
202+
const viewData = this.data[name][index];
203+
const hooks = this.model.views[name].hooks || [];
204+
hooks.forEach((hook) =>
205+
HookManager.applyHook(hook, this.fullData, viewData, this.model)
206+
);
207+
}
208+
209+
// --------
210+
198211
getPropertyList() {
199212
const propertyList = [];
200213

0 commit comments

Comments
 (0)