rename afterFlush to nextTick, schedule update if necessary

pull/1988/head
Richard Harris 6 years ago
parent 097507796d
commit c266051811

@ -3,6 +3,6 @@ export {
onDestroy,
beforeUpdate,
afterUpdate,
add_render_callback as afterFlush,
nextTick,
createEventDispatcher
} from './internal';

@ -1,4 +1,4 @@
import { add_render_callback, flush, intros, schedule_update } from './scheduler.js';
import { add_render_callback, flush, intros, schedule_update, dirty_components } from './scheduler.js';
import { current_component, set_current_component } from './lifecycle.js'
import { is_function, run, run_all, noop } from './utils.js';
import { blankObject } from './utils.js';
@ -46,7 +46,8 @@ function destroy(component, detach) {
function make_dirty(component, key) {
if (!component.$$.dirty) {
schedule_update(component);
dirty_components.push(component);
schedule_update();
component.$$.dirty = {};
}
component.$$.dirty[key] = true;

@ -1,15 +1,13 @@
import { run_all } from './utils.js';
let update_scheduled = false;
export let dirty_components = [];
export const intros = { enabled: false };
let dirty_components = [];
let update_scheduled = false;
const binding_callbacks = [];
const render_callbacks = [];
export const intros = { enabled: false };
export function schedule_update(component) {
dirty_components.push(component);
export function schedule_update() {
if (!update_scheduled) {
update_scheduled = true;
queue_microtask(flush);
@ -20,6 +18,11 @@ export function add_render_callback(fn) {
render_callbacks.push(fn);
}
export function nextTick(fn) {
add_render_callback(fn);
schedule_update();
}
export function add_binding_callback(fn) {
binding_callbacks.push(fn);
}

@ -1,20 +0,0 @@
export default {
async test({ assert, component, target, window }) {
const button = target.querySelector('button');
const click = new window.MouseEvent('click');
await button.dispatchEvent(click);
assert.deepEqual(component.snapshots, [
'before 0',
'after 1'
]);
await button.dispatchEvent(click);
assert.deepEqual(component.snapshots, [
'before 0',
'after 1',
'before 1',
'after 2'
]);
}
};

@ -1,19 +0,0 @@
<script>
import { afterFlush } from 'svelte';
export let snapshots = [];
let count = 0;
let button;
function click() {
count += 1;
snapshots.push(`before ${button.textContent}`);
afterFlush(() => {
snapshots.push(`after ${button.textContent}`);
});
}
</script>
<button bind:this={button} on:click={click}>{count}</button>

@ -0,0 +1,30 @@
export default {
async test({ assert, component, target, window }) {
const buttons = target.querySelectorAll('button');
const click = new window.MouseEvent('click');
await buttons[0].dispatchEvent(click);
assert.deepEqual(component.snapshots, [
'before 0',
'after 1'
]);
await buttons[0].dispatchEvent(click);
assert.deepEqual(component.snapshots, [
'before 0',
'after 1',
'before 1',
'after 2'
]);
await buttons[1].dispatchEvent(click);
assert.deepEqual(component.snapshots, [
'before 0',
'after 1',
'before 1',
'after 2',
'before 2',
'after 2'
]);
}
};

@ -0,0 +1,24 @@
<script>
import { nextTick } from 'svelte';
export let snapshots = [];
let count = 0;
let buttons = [];
function increment() {
count += 1;
log();
}
function log() {
snapshots.push(`before ${buttons[0].textContent}`);
nextTick(() => {
snapshots.push(`after ${buttons[0].textContent}`);
});
}
</script>
<button bind:this={buttons[0]} on:click={increment}>{count}</button>
<button bind:this={buttons[1]} on:click={log}>{count}</button>
Loading…
Cancel
Save