Merge branch 'master' of github.com:sveltejs/svelte

pull/2341/head
Richard Harris 5 years ago
commit 143117054a

@ -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() {
};
});
return function stop() {};
});

@ -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());
});

@ -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 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` 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());
```
});
```

@ -95,8 +95,8 @@ export default async function preprocess(
for (const fn of script) {
source = await replace_async(
source,
/<script([^]*?)>([^]*?)<\/script>/gi,
async (match, attributes, content) => {
/<script(\s[^]*?)?>([^]*?)<\/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([^]*?)>([^]*?)<\/style>/gi,
async (match, attributes, content) => {
/<style(\s[^]*?)?>([^]*?)<\/style>/gi,
async (match, attributes = '', content) => {
const processed: Processed = await fn({
content,
attributes: parse_attributes(attributes),

@ -0,0 +1,6 @@
export default {
preprocess: {
script: () => ({ code: '' }),
style: () => ({ code: '' })
}
};

@ -0,0 +1,12 @@
<script-foo>
foo
</script-foo>
<script>
// bar
</script>
<style-foo>
foo
</style-foo>
<style>
bar {}
</style>

@ -0,0 +1,8 @@
<script-foo>
foo
</script-foo>
<script></script>
<style-foo>
foo
</style-foo>
<style></style>
Loading…
Cancel
Save