fixes sequential order

pull/3308/head
deviprsd 6 years ago
parent b99ee7d5d1
commit 9a154e0d3b

2
package-lock.json generated

@ -1,6 +1,6 @@
{ {
"name": "svelte", "name": "svelte",
"version": "3.6.7", "version": "3.6.9",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

@ -35,15 +35,18 @@ export function flush() {
const seen_callbacks = new Set(); const seen_callbacks = new Set();
do { do {
// first, call beforeUpdate functions do {
// and update components // check dirty bindings first
while (dirty_components.length) { while (binding_callbacks.length) binding_callbacks.pop()();
const component = dirty_components.shift();
set_current_component(component); // then call beforeUpdate functions
update(component.$$); // and update components
} while (dirty_components.length) {
const component = dirty_components.shift();
while (binding_callbacks.length) binding_callbacks.pop()(); set_current_component(component);
update(component.$$);
}
} while (binding_callbacks.length);
// then, once components are updated, call // then, once components are updated, call
// afterUpdate functions. This may cause // afterUpdate functions. This may cause

@ -0,0 +1,23 @@
export default {
html: `<div>bind</div>`,
async test({ assert, component, target }) {
assert.equal(component.ref, target.querySelector('div'));
assert.equal(component.hooks[0], 'Before');
assert.equal(component.hooks.pop(), 'After');
while (component.hooks.length) component.hooks.pop();
component.bind = false;
assert.equal(component.ref, null);
assert.equal(component.hooks[0], 'Before');
assert.equal(component.hooks.pop(), 'After');
while (component.hooks.length) component.hooks.pop();
component.bind = true;
assert.equal(component.ref, target.querySelector('div'));
assert.equal(component.hooks[0], 'Before');
assert.equal(component.hooks.pop(), 'After');
}
};

@ -0,0 +1,15 @@
<script>
// adapted from https://svelte.dev/repl/8a96e6e545244bff9fd0125b152d6840?version=3.6.9
import { afterUpdate, beforeUpdate, onMount } from 'svelte';
export let ref = null, bind = true, hooks = [];
// using push to not make hooks reactive
beforeUpdate(() => hooks.push('Before'))
afterUpdate(() => hooks.push('After'))
onMount(() => hooks.push('Mount'))
</script>
{#if bind}
<div bind:this={ref}>bind</div>
{/if}
Loading…
Cancel
Save