From 0bb40196db72c7166fa2a6e6715808d3bb2a83e3 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Thu, 12 Dec 2019 21:40:03 +0800 Subject: [PATCH] fix invalidate while update --- src/runtime/internal/scheduler.ts | 3 +- .../_config.js | 44 +++++++++++++++++++ .../main.svelte | 20 +++++++++ .../_config.js | 44 +++++++++++++++++++ .../main.svelte | 20 +++++++++ 5 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/store-invalidation-while-update-1/_config.js create mode 100644 test/runtime/samples/store-invalidation-while-update-1/main.svelte create mode 100644 test/runtime/samples/store-invalidation-while-update-2/_config.js create mode 100644 test/runtime/samples/store-invalidation-while-update-2/main.svelte diff --git a/src/runtime/internal/scheduler.ts b/src/runtime/internal/scheduler.ts index 2f864743a2..04c1264ab1 100644 --- a/src/runtime/internal/scheduler.ts +++ b/src/runtime/internal/scheduler.ts @@ -73,8 +73,9 @@ function update($$) { if ($$.fragment !== null) { $$.update(); run_all($$.before_update); - $$.fragment && $$.fragment.p($$.ctx, $$.dirty); + const dirty = $$.dirty; $$.dirty = [-1]; + $$.fragment && $$.fragment.p($$.ctx, dirty); $$.after_update.forEach(add_render_callback); } diff --git a/test/runtime/samples/store-invalidation-while-update-1/_config.js b/test/runtime/samples/store-invalidation-while-update-1/_config.js new file mode 100644 index 0000000000..d0361d2d23 --- /dev/null +++ b/test/runtime/samples/store-invalidation-while-update-1/_config.js @@ -0,0 +1,44 @@ +export default { + html: ` + +
+
simple
+ + `, + + async test({ assert, component, target, window }) { + const input = target.querySelector('input'); + const button = target.querySelector('button'); + + const inputEvent = new window.InputEvent('input'); + const clickEvent = new window.MouseEvent('click'); + + input.value = 'foo'; + await input.dispatchEvent(inputEvent); + + assert.htmlEqual(target.innerHTML, ` + +
foo
+
foo
+ + `); + + await button.dispatchEvent(clickEvent); + assert.htmlEqual(target.innerHTML, ` + +
foo
+
clicked
+ + `); + + input.value = 'bar'; + await input.dispatchEvent(inputEvent); + + assert.htmlEqual(target.innerHTML, ` + +
bar
+
bar
+ + `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/store-invalidation-while-update-1/main.svelte b/test/runtime/samples/store-invalidation-while-update-1/main.svelte new file mode 100644 index 0000000000..f74808ee2e --- /dev/null +++ b/test/runtime/samples/store-invalidation-while-update-1/main.svelte @@ -0,0 +1,20 @@ + + + +
{v}
+
{$s}
+ diff --git a/test/runtime/samples/store-invalidation-while-update-2/_config.js b/test/runtime/samples/store-invalidation-while-update-2/_config.js new file mode 100644 index 0000000000..422034bc11 --- /dev/null +++ b/test/runtime/samples/store-invalidation-while-update-2/_config.js @@ -0,0 +1,44 @@ +export default { + html: ` +
+
simple
+ + + `, + + async test({ assert, component, target, window }) { + const input = target.querySelector('input'); + const button = target.querySelector('button'); + + const inputEvent = new window.InputEvent('input'); + const clickEvent = new window.MouseEvent('click'); + + input.value = 'foo'; + await input.dispatchEvent(inputEvent); + + assert.htmlEqual(target.innerHTML, ` +
foo
+
foo
+ + + `); + + await button.dispatchEvent(clickEvent); + assert.htmlEqual(target.innerHTML, ` +
foo
+
clicked
+ + + `); + + input.value = 'bar'; + await input.dispatchEvent(inputEvent); + + assert.htmlEqual(target.innerHTML, ` +
bar
+
bar
+ + + `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/store-invalidation-while-update-2/main.svelte b/test/runtime/samples/store-invalidation-while-update-2/main.svelte new file mode 100644 index 0000000000..83e13742ce --- /dev/null +++ b/test/runtime/samples/store-invalidation-while-update-2/main.svelte @@ -0,0 +1,20 @@ + + +
{v}
+
{$s}
+ +