From 7f97f954b28fcc81eb1cb67bf800ad473294d95a Mon Sep 17 00:00:00 2001 From: daszgfz Date: Wed, 11 Sep 2019 16:56:00 -0400 Subject: [PATCH] add tests for store invalidate refactor --- .../expected.js | 63 +++++++++++++++ .../input.svelte | 6 ++ .../expected.js | 79 +++++++++++++++++++ .../input.svelte | 7 ++ 4 files changed, 155 insertions(+) create mode 100644 test/js/samples/component-store-access-invalidate/expected.js create mode 100644 test/js/samples/component-store-access-invalidate/input.svelte create mode 100644 test/js/samples/component-store-reassign-invalidate/expected.js create mode 100644 test/js/samples/component-store-reassign-invalidate/input.svelte diff --git a/test/js/samples/component-store-access-invalidate/expected.js b/test/js/samples/component-store-access-invalidate/expected.js new file mode 100644 index 0000000000..e332a0dbb5 --- /dev/null +++ b/test/js/samples/component-store-access-invalidate/expected.js @@ -0,0 +1,63 @@ +/* generated by Svelte vX.Y.Z */ +import { + SvelteComponent, + append, + component_subscribe, + detach, + element, + init, + insert, + noop, + safe_not_equal, + set_data, + text +} from "svelte/internal"; +import { writable } from "svelte/store"; + +function create_fragment(ctx) { + var h1, t; + + return { + c() { + h1 = element("h1"); + t = text(ctx.$foo); + }, + + m(target, anchor) { + insert(target, h1, anchor); + append(h1, t); + }, + + p(changed, ctx) { + if (changed.$foo) { + set_data(t, ctx.$foo); + } + }, + + i: noop, + o: noop, + + d(detaching) { + if (detaching) { + detach(h1); + } + } + }; +} + +function instance($$self, $$props, $$invalidate) { + let $foo; + + const foo = writable(0); component_subscribe($$self, foo, $$value => $$invalidate('$foo', $foo = $$value)); + + return { foo, $foo }; +} + +class Component extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance, create_fragment, safe_not_equal, []); + } +} + +export default Component; \ No newline at end of file diff --git a/test/js/samples/component-store-access-invalidate/input.svelte b/test/js/samples/component-store-access-invalidate/input.svelte new file mode 100644 index 0000000000..f42bbe295c --- /dev/null +++ b/test/js/samples/component-store-access-invalidate/input.svelte @@ -0,0 +1,6 @@ + + +

{$foo}

\ No newline at end of file diff --git a/test/js/samples/component-store-reassign-invalidate/expected.js b/test/js/samples/component-store-reassign-invalidate/expected.js new file mode 100644 index 0000000000..31215da1f9 --- /dev/null +++ b/test/js/samples/component-store-reassign-invalidate/expected.js @@ -0,0 +1,79 @@ +/* generated by Svelte vX.Y.Z */ +import { + SvelteComponent, + append, + detach, + element, + init, + insert, + listen, + noop, + safe_not_equal, + set_data, + space, + subscribe, + text +} from "svelte/internal"; +import { writable } from "svelte/store"; + +function create_fragment(ctx) { + var h1, t0, t1, button, dispose; + + return { + c() { + h1 = element("h1"); + t0 = text(ctx.$foo); + t1 = space(); + button = element("button"); + button.textContent = "reset"; + dispose = listen(button, "click", ctx.click_handler); + }, + + m(target, anchor) { + insert(target, h1, anchor); + append(h1, t0); + insert(target, t1, anchor); + insert(target, button, anchor); + }, + + p(changed, ctx) { + if (changed.$foo) { + set_data(t0, ctx.$foo); + } + }, + + i: noop, + o: noop, + + d(detaching) { + if (detaching) { + detach(h1); + detach(t1); + detach(button); + } + + dispose(); + } + }; +} + +function instance($$self, $$props, $$invalidate) { + let $foo, $$unsubscribe_foo = noop, $$subscribe_foo = () => ($$unsubscribe_foo(), $$unsubscribe_foo = subscribe(foo, $$value => $$invalidate('$foo', $foo = $$value)), foo); + + $$self.$$.on_destroy.push(() => $$unsubscribe_foo()); + + let foo = writable(0); $$subscribe_foo(); + + const click_handler = () => $$subscribe_foo($$invalidate('foo', foo = writable(0))); + + return { foo, $foo, click_handler }; +} + +class Component extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance, create_fragment, safe_not_equal, []); + } +} + +export default Component; \ No newline at end of file diff --git a/test/js/samples/component-store-reassign-invalidate/input.svelte b/test/js/samples/component-store-reassign-invalidate/input.svelte new file mode 100644 index 0000000000..bbb52b9669 --- /dev/null +++ b/test/js/samples/component-store-reassign-invalidate/input.svelte @@ -0,0 +1,7 @@ + + +

{$foo}

+ \ No newline at end of file