From e76b9e779a28f4dc2430e934f5388d41313bf30e Mon Sep 17 00:00:00 2001 From: James Date: Thu, 28 Mar 2019 21:56:11 +0800 Subject: [PATCH 1/3] reverse readable stores arg order, fixes #2330 --- .../tutorial/08-stores/03-readable-stores/app-a/stores.js | 8 +++----- .../tutorial/08-stores/03-readable-stores/app-b/stores.js | 4 ++-- .../content/tutorial/08-stores/03-readable-stores/text.md | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/site/content/tutorial/08-stores/03-readable-stores/app-a/stores.js b/site/content/tutorial/08-stores/03-readable-stores/app-a/stores.js index 1e5d11e2d9..ec0a749d79 100644 --- a/site/content/tutorial/08-stores/03-readable-stores/app-a/stores.js +++ b/site/content/tutorial/08-stores/03-readable-stores/app-a/stores.js @@ -1,9 +1,7 @@ import { readable } from 'svelte/store'; -export const time = readable(function start(set) { +export const time = readable(null, function start(set) { // implementation goes here - return function stop() { - - }; -}); \ No newline at end of file + return function stop() {}; +}); diff --git a/site/content/tutorial/08-stores/03-readable-stores/app-b/stores.js b/site/content/tutorial/08-stores/03-readable-stores/app-b/stores.js index 015de5ad45..8c11f6d3aa 100644 --- a/site/content/tutorial/08-stores/03-readable-stores/app-b/stores.js +++ b/site/content/tutorial/08-stores/03-readable-stores/app-b/stores.js @@ -1,6 +1,6 @@ import { readable } from 'svelte/store'; -export const time = readable(function start(set) { +export const time = readable(new Date(), function start(set) { const interval = setInterval(() => { set(new Date()); }, 1000); @@ -8,4 +8,4 @@ export const time = readable(function start(set) { return function stop() { clearInterval(interval); }; -}, new Date()); \ No newline at end of file +}); diff --git a/site/content/tutorial/08-stores/03-readable-stores/text.md b/site/content/tutorial/08-stores/03-readable-stores/text.md index 6ef989fffa..c3bd310dd6 100644 --- a/site/content/tutorial/08-stores/03-readable-stores/text.md +++ b/site/content/tutorial/08-stores/03-readable-stores/text.md @@ -4,7 +4,7 @@ title: Readable stores Not all stores should be writable by whoever has a reference to them. For example, you might have a store representing the mouse position or the user's geolocation, and it doesn't make sense to be able to set those values from 'outside'. For those cases, we have *readable* stores. -Click over to the `stores.js` tab. The first argument to `readable` is a `start` function that takes a `set` callback and returns a `stop` function. The `start` function is called when the store gets its first subscriber; `stop` is called when the last subscriber unsubscribes. The second (optional) argument is the initial value. +Click over to the `stores.js` tab. The first argument to `readable` is an initial value, which can be null. The second argument is a `start` function that takes a `set` callback and returns a `stop` function. The `start` function is called when the store gets its first subscriber; `stop` is called when the last subscriber unsubscribes. ```js export const time = readable(function start(set) { From ef9c9a626e70a7c3ff684388365ee119670ce8f8 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 28 Mar 2019 10:54:46 -0400 Subject: [PATCH 2/3] don't preprocess tags whose names begin with script/style --- src/preprocess/index.ts | 8 ++++---- test/preprocess/samples/partial-names/_config.js | 6 ++++++ test/preprocess/samples/partial-names/input.svelte | 12 ++++++++++++ test/preprocess/samples/partial-names/output.svelte | 8 ++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 test/preprocess/samples/partial-names/_config.js create mode 100644 test/preprocess/samples/partial-names/input.svelte create mode 100644 test/preprocess/samples/partial-names/output.svelte diff --git a/src/preprocess/index.ts b/src/preprocess/index.ts index 8538a65acc..2666e5fb7f 100644 --- a/src/preprocess/index.ts +++ b/src/preprocess/index.ts @@ -95,8 +95,8 @@ export default async function preprocess( for (const fn of script) { source = await replace_async( source, - /([^]*?)<\/script>/gi, - async (match, attributes, content) => { + /([^]*?)<\/script>/gi, + async (match, attributes = '', content) => { const processed: Processed = await fn({ content, attributes: parse_attributes(attributes), @@ -111,8 +111,8 @@ export default async function preprocess( for (const fn of style) { source = await replace_async( source, - /([^]*?)<\/style>/gi, - async (match, attributes, content) => { + /([^]*?)<\/style>/gi, + async (match, attributes = '', content) => { const processed: Processed = await fn({ content, attributes: parse_attributes(attributes), diff --git a/test/preprocess/samples/partial-names/_config.js b/test/preprocess/samples/partial-names/_config.js new file mode 100644 index 0000000000..dadf801581 --- /dev/null +++ b/test/preprocess/samples/partial-names/_config.js @@ -0,0 +1,6 @@ +export default { + preprocess: { + script: () => ({ code: '' }), + style: () => ({ code: '' }) + } +}; diff --git a/test/preprocess/samples/partial-names/input.svelte b/test/preprocess/samples/partial-names/input.svelte new file mode 100644 index 0000000000..6875a491a0 --- /dev/null +++ b/test/preprocess/samples/partial-names/input.svelte @@ -0,0 +1,12 @@ + + foo + + + + foo + + diff --git a/test/preprocess/samples/partial-names/output.svelte b/test/preprocess/samples/partial-names/output.svelte new file mode 100644 index 0000000000..34c789a826 --- /dev/null +++ b/test/preprocess/samples/partial-names/output.svelte @@ -0,0 +1,8 @@ + + foo + + + + foo + + From 4be340bb57f528a13a7257ea5d126c0244aceb4f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 29 Mar 2019 08:28:29 -0400 Subject: [PATCH 3/3] fix example code --- .../content/tutorial/08-stores/03-readable-stores/text.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/site/content/tutorial/08-stores/03-readable-stores/text.md b/site/content/tutorial/08-stores/03-readable-stores/text.md index c3bd310dd6..25c02a9c0a 100644 --- a/site/content/tutorial/08-stores/03-readable-stores/text.md +++ b/site/content/tutorial/08-stores/03-readable-stores/text.md @@ -4,10 +4,10 @@ title: Readable stores Not all stores should be writable by whoever has a reference to them. For example, you might have a store representing the mouse position or the user's geolocation, and it doesn't make sense to be able to set those values from 'outside'. For those cases, we have *readable* stores. -Click over to the `stores.js` tab. The first argument to `readable` is an initial value, which can be null. The second argument is a `start` function that takes a `set` callback and returns a `stop` function. The `start` function is called when the store gets its first subscriber; `stop` is called when the last subscriber unsubscribes. +Click over to the `stores.js` tab. The first argument to `readable` is an initial value, which can be `null` or `undefined` if you don't have one yet. The second argument is a `start` function that takes a `set` callback and returns a `stop` function. The `start` function is called when the store gets its first subscriber; `stop` is called when the last subscriber unsubscribes. ```js -export const time = readable(function start(set) { +export const time = readable(new Date(), function start(set) { const interval = setInterval(() => { set(new Date()); }, 1000); @@ -15,5 +15,5 @@ export const time = readable(function start(set) { return function stop() { clearInterval(interval); }; -}, new Date()); -``` \ No newline at end of file +}); +```