enforce order of operations

pull/709/head
Rich Harris 8 years ago
parent d893f8fc28
commit 0a806585b3

@ -235,9 +235,15 @@ export default function dom(
this._fragment.${block.hasIntroMethod ? 'intro' : 'mount'}( options.target, null ); this._fragment.${block.hasIntroMethod ? 'intro' : 'mount'}( options.target, null );
} }
${(generator.hasComponents || generator.hasComplexBindings) && `@callAll(this._beforecreate);`} ${(generator.hasComponents || generator.hasComplexBindings || templateProperties.oncreate || generator.hasIntroTransitions) && deindent`
${(generator.hasComponents || templateProperties.oncreate) && `@callAll(this._oncreate);`} if ( !options._root ) {
${(generator.hasComponents || generator.hasIntroTransitions) && `@callAll(this._aftercreate);`} ${generator.hasComponents && `this._block = true;`}
${(generator.hasComponents || generator.hasComplexBindings) && `@callAll(this._beforecreate);`}
${(generator.hasComponents || templateProperties.oncreate) && `@callAll(this._oncreate);`}
${(generator.hasComponents || generator.hasIntroTransitions) && `@callAll(this._aftercreate);`}
${generator.hasComponents && `this._block = false;`}
}
`}
} }
@assign( ${prototypeBase}, ${proto}); @assign( ${prototypeBase}, ${proto});

@ -27,10 +27,10 @@ export default function getSetter({
list[index]${tail} = ${value}; list[index]${tail} = ${value};
${computed ${computed
? `#component._set({ ${dependencies ? `#component.set({ ${dependencies
.map((prop: string) => `${prop}: state.${prop}`) .map((prop: string) => `${prop}: state.${prop}`)
.join(', ')} });` .join(', ')} });`
: `#component._set({ ${dependencies : `#component.set({ ${dependencies
.map((prop: string) => `${prop}: #component.get( '${prop}' )`) .map((prop: string) => `${prop}: #component.get( '${prop}' )`)
.join(', ')} });`} .join(', ')} });`}
`; `;
@ -40,13 +40,13 @@ export default function getSetter({
return deindent` return deindent`
var state = #component.get(); var state = #component.get();
${snippet} = ${value}; ${snippet} = ${value};
#component._set({ ${dependencies #component.set({ ${dependencies
.map((prop: string) => `${prop}: state.${prop}`) .map((prop: string) => `${prop}: state.${prop}`)
.join(', ')} }); .join(', ')} });
`; `;
} }
return `#component._set({ ${name}: ${value} });`; return `#component.set({ ${name}: ${value} });`;
} }
function isComputed(node: Node) { function isComputed(node: Node) {

@ -106,9 +106,12 @@ export function onDev(eventName, handler) {
export function set(newState) { export function set(newState) {
this._set(assign({}, newState)); this._set(assign({}, newState));
if (this._root._block) return;
this._root._block = true;
callAll(this._root._beforecreate); callAll(this._root._beforecreate);
callAll(this._root._oncreate); callAll(this._root._oncreate);
callAll(this._root._aftercreate); callAll(this._root._aftercreate);
this._root._block = false;
} }
export function callAll(fns) { export function callAll(fns) {

Loading…
Cancel
Save