[docs] 04-custom-stores: naming update, snake_case replaced to camelCase

pull/7180/head
nazar-lazarchuk 5 years ago
parent 9a28199d79
commit bb147ea594

@ -1,9 +1,9 @@
<script> <script>
import { count } from './stores.js'; import { counter } from './stores.js';
</script> </script>
<h1>The count is {$count}</h1> <h1>The counter is {$counter}</h1>
<button on:click={count.increment}>+</button> <button on:click={counter.increment}>+</button>
<button on:click={count.decrement}>-</button> <button on:click={counter.decrement}>-</button>
<button on:click={count.reset}>reset</button> <button on:click={counter.reset}>reset</button>

@ -1,6 +1,6 @@
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
function createCount() { function createCounter() {
const { subscribe, set, update } = writable(0); const { subscribe, set, update } = writable(0);
return { return {
@ -11,4 +11,4 @@ function createCount() {
}; };
} }
export const count = createCount(); export const counter = createCounter();

@ -1,9 +1,9 @@
<script> <script>
import { count } from './stores.js'; import { counter } from './stores.js';
</script> </script>
<h1>The count is {$count}</h1> <h1>The counter is {$counter}</h1>
<button on:click={count.increment}>+</button> <button on:click={counter.increment}>+</button>
<button on:click={count.decrement}>-</button> <button on:click={counter.decrement}>-</button>
<button on:click={count.reset}>reset</button> <button on:click={counter.reset}>reset</button>

@ -1,6 +1,6 @@
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
function createCount() { function createCounter() {
const { subscribe, set, update } = writable(0); const { subscribe, set, update } = writable(0);
return { return {
@ -11,4 +11,4 @@ function createCount() {
}; };
} }
export const count = createCount(); export const counter = createCounter();

@ -1,9 +1,9 @@
<script> <script>
import { count } from './stores.js'; import { counter } from './stores.js';
</script> </script>
<h1>The count is {$count}</h1> <h1>The counter is {$counter}</h1>
<button on:click={count.increment}>+</button> <button on:click={counter.increment}>+</button>
<button on:click={count.decrement}>-</button> <button on:click={counter.decrement}>-</button>
<button on:click={count.reset}>reset</button> <button on:click={counter.reset}>reset</button>

@ -1,6 +1,6 @@
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
function createCount() { function createCounter() {
const { subscribe, set, update } = writable(0); const { subscribe, set, update } = writable(0);
return { return {
@ -11,4 +11,4 @@ function createCount() {
}; };
} }
export const count = createCount(); export const counter = createCounter();

@ -4,10 +4,10 @@ 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. 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 `counter` store from our earlier example could include `increment`, `decrement` and `reset` methods and avoid exposing `set` and `update`:
```js ```js
function createCount() { function createCounter() {
const { subscribe, set, update } = writable(0); const { subscribe, set, update } = writable(0);
return { return {

Loading…
Cancel
Save