Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix #714 #715

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/generators/dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export default function dom(
${computations.length &&
`@recompute( this._state, newState, oldState, false )`}
@dispatchObservers( this, this._observers.pre, newState, oldState );
${block.hasUpdateMethod && `this._fragment.update( newState, this._state );`}

${block.hasUpdateMethod && `withoutDomUpdate || this._fragment.update( newState, this._state );`}
@dispatchObservers( this, this._observers.post, newState, oldState );
${generator.hasComponents && `@callAll(this._oncreate);`}
${generator.hasComplexBindings && `@callAll(this._bindings);`}
Expand Down Expand Up @@ -213,6 +214,7 @@ export default function dom(

this._fragment = @create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
${generator.hydratable
? deindent`
Expand All @@ -225,10 +227,13 @@ export default function dom(
this._fragment.create();
`}
this._fragment.${block.hasIntroMethod ? 'intro' : 'mount'}( options.target, null );
} else {
this._protectDomUpdate = true;
}

${generator.hasComponents && `@callAll(this._oncreate);`}
${generator.hasComplexBindings && `@callAll(this._bindings);`}
this._protectDomUpdate = false;

${templateProperties.oncreate && deindent`
if ( options._root ) {
Expand All @@ -242,7 +247,7 @@ export default function dom(

@assign( ${prototypeBase}, ${proto});

${name}.prototype._set = function _set ( newState ) {
${name}.prototype._set = function _set ( newState, withoutDomUpdate ) {
${_set}
};

Expand Down
8 changes: 4 additions & 4 deletions src/generators/dom/visitors/shared/binding/getSetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export default function getSetter({
${computed
? `#component._set({ ${dependencies
.map((prop: string) => `${prop}: state.${prop}`)
.join(', ')} });`
.join(', ')} }, #component._protectDomUpdate);`
: `#component._set({ ${dependencies
.map((prop: string) => `${prop}: #component.get( '${prop}' )`)
.join(', ')} });`}
.join(', ')} }, #component._protectDomUpdate);`}
`;
}

Expand All @@ -42,11 +42,11 @@ export default function getSetter({
${snippet} = ${value};
#component._set({ ${dependencies
.map((prop: string) => `${prop}: state.${prop}`)
.join(', ')} });
.join(', ')} }, #component._protectDomUpdate);
`;
}

return `#component._set({ ${name}: ${value} });`;
return `#component._set({ ${name}: ${value} }, #component._protectDomUpdate);`;
}

function isComputed(node: Node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,24 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
this._fragment.update( newState, this._state );

withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};

Expand Down
9 changes: 7 additions & 2 deletions test/js/samples/collapses-text-around-comments/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,24 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
this._fragment.update( newState, this._state );

withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};

Expand Down
6 changes: 5 additions & 1 deletion test/js/samples/computed-collapsed-if/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,19 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
recompute( this._state, newState, oldState, false );
Expand Down
6 changes: 5 additions & 1 deletion test/js/samples/computed-collapsed-if/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
recompute( this._state, newState, oldState, false )
Expand Down
9 changes: 7 additions & 2 deletions test/js/samples/each-block-changed-check/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,24 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
this._fragment.update( newState, this._state );

withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};

Expand Down
9 changes: 7 additions & 2 deletions test/js/samples/each-block-changed-check/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,24 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
this._fragment.update( newState, this._state );

withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};

Expand Down
6 changes: 5 additions & 1 deletion test/js/samples/event-handlers-custom/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,19 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, template.methods, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
Expand Down
6 changes: 5 additions & 1 deletion test/js/samples/event-handlers-custom/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, template.methods, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
Expand Down
9 changes: 7 additions & 2 deletions test/js/samples/if-block-no-update/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,24 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
this._fragment.update( newState, this._state );

withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};

Expand Down
9 changes: 7 additions & 2 deletions test/js/samples/if-block-no-update/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,24 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
this._fragment.update( newState, this._state );

withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};

Expand Down
9 changes: 7 additions & 2 deletions test/js/samples/if-block-simple/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,24 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
this._fragment.update( newState, this._state );

withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};

Expand Down
9 changes: 7 additions & 2 deletions test/js/samples/if-block-simple/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,24 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
this._fragment.update( newState, this._state );

withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};

Expand Down
6 changes: 5 additions & 1 deletion test/js/samples/non-imported-component/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,21 @@ function SvelteComponent ( options ) {

this._fragment = create_main_fragment( this._state, this );

this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
} else {
this._protectDomUpdate = true;
}

callAll(this._oncreate);
this._protectDomUpdate = false;
}

assign( SvelteComponent.prototype, proto );

SvelteComponent.prototype._set = function _set ( newState ) {
SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
Expand Down
Loading