Extend "Custom stores" example & tutorial

Extended custom store example for passing data to a method.
pull/3720/head
Torsten Dittmann 6 years ago
parent b9f14846b0
commit 82d84abfce

@ -6,4 +6,5 @@
<button on:click={count.increment}>+</button>
<button on:click={count.decrement}>-</button>
<button on:click={() => count.change(12)}>set to 12</button>
<button on:click={count.reset}>reset</button>

@ -7,6 +7,7 @@ function createCount() {
subscribe,
increment: () => update(n => n + 1),
decrement: () => update(n => n - 1),
change: (parameter) => set(parameter),
reset: () => set(0)
};
}

@ -6,4 +6,5 @@
<button on:click={count.increment}>+</button>
<button on:click={count.decrement}>-</button>
<button on:click={count.change}>set to 12</button>
<button on:click={count.reset}>reset</button>

@ -7,6 +7,7 @@ function createCount() {
subscribe,
increment: () => {},
decrement: () => {},
change: () => {},
reset: () => {}
};
}

@ -6,4 +6,5 @@
<button on:click={count.increment}>+</button>
<button on:click={count.decrement}>-</button>
<button on:click={() => count.change(12)}>set to 12</button>
<button on:click={count.reset}>reset</button>

@ -7,6 +7,7 @@ function createCount() {
subscribe,
increment: () => update(n => n + 1),
decrement: () => update(n => n - 1),
change: (parameter) => set(parameter),
reset: () => set(0)
};
}

@ -4,7 +4,7 @@ title: Custom stores
As long as an object correctly implements the `subscribe` method, it's a store. Beyond that, anything goes. It's very easy, therefore, to create custom stores with domain-specific logic.
For example, the `count` store from our earlier example could include `increment`, `decrement` and `reset` methods and avoid exposing `set` and `update`:
For example, the `count` store from our earlier example could include `increment`, `decrement`, `change` and `reset` methods and avoid exposing `set` and `update`:
```js
function createCount() {
@ -14,6 +14,7 @@ function createCount() {
subscribe,
increment: () => update(n => n + 1),
decrement: () => update(n => n - 1),
change: (parameter) => set(parameter),
reset: () => set(0)
};
}

Loading…
Cancel
Save