expose add_render_callback as afterFlush - fixes #1976

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

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

@ -0,0 +1,20 @@
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'
]);
}
};

@ -0,0 +1,19 @@
<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>
Loading…
Cancel
Save