Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend "Custom stores" example & tutorial #3720

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 1 addition & 0 deletions site/content/examples/07-stores/04-custom-stores/stores.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function createCount() {
subscribe,
increment: () => update(n => n + 1),
decrement: () => update(n => n - 1),
change: (parameter) => set(parameter),
reset: () => set(0)
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function createCount() {
subscribe,
increment: () => {},
decrement: () => {},
change: () => {},
reset: () => {}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function createCount() {
subscribe,
increment: () => update(n => n + 1),
decrement: () => update(n => n - 1),
change: (parameter) => set(parameter),
reset: () => set(0)
};
}
Expand Down
3 changes: 2 additions & 1 deletion site/content/tutorial/08-stores/05-custom-stores/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -14,6 +14,7 @@ function createCount() {
subscribe,
increment: () => update(n => n + 1),
decrement: () => update(n => n - 1),
change: (parameter) => set(parameter),
reset: () => set(0)
};
}
Expand Down