Merge pull request #921 from sveltejs/gh-917

check component exists after _bind before continuing
pull/933/head
Rich Harris 8 years ago committed by GitHub
commit 0a4e795498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -156,10 +156,13 @@ export function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
export function _setDev(newState) { export function _setDev(newState) {
if (typeof newState !== 'object') { if (typeof newState !== 'object') {

@ -157,10 +157,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -133,10 +133,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -133,10 +133,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -153,10 +153,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -145,10 +145,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -165,10 +165,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -145,10 +145,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -149,10 +149,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -149,10 +149,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -149,10 +149,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -149,10 +149,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -149,10 +149,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -149,10 +149,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -153,10 +153,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -151,10 +151,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -168,10 +168,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -161,10 +161,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -147,10 +147,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -133,10 +133,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -133,10 +133,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -157,10 +157,13 @@ function _set(newState) {
this._state = assign({}, oldState, newState); this._state = assign({}, oldState, newState);
this._recompute(changed, this._state); this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state); if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState); dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state); this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState); dispatchObservers(this, this._observers.post, changed, this._state, oldState);
} }
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.pop()(); while (fns && fns.length) fns.pop()();

@ -0,0 +1 @@
<button on:click="set({show:false})">Hide</button>

@ -0,0 +1,27 @@
export default {
data: {
show: true
},
html: `
<button>Hide</button>
`,
test(assert, component, target, window) {
const click = new window.MouseEvent('click');
target.querySelector('button').dispatchEvent(click);
assert.equal(component.get('show'), false);
assert.htmlEqual(target.innerHTML, `
<button>Show</button>
`);
target.querySelector('button').dispatchEvent(click);
assert.equal(component.get('show'), true);
assert.htmlEqual(target.innerHTML, `
<button>Hide</button>
`);
}
};

@ -0,0 +1,14 @@
{{#if show}}
<Nested bind:show/>
{{else}}
<button on:click="set({show:true})">Show</button>
{{/if}}
<script>
import Nested from './Nested.html';
export default {
components: {
Nested
}
};
</script>
Loading…
Cancel
Save