DEV.log

custom-stores 본문

Svelte/tutorial

custom-stores

magnae2016 2022. 2. 1. 11:38
<!-- App.svelte -->
<script>
	import { count } from './stores.js';
</script>

<h1>The count is {$count}</h1>

<button on:click={count.increment}>+</button>
<button on:click={count.decrement}>-</button>
<button on:click={count.reset}>reset</button>
// stores.js
import { writable } from 'svelte/store';

function createCount() {
	const { subscribe, set, update } = writable(0);

	return {
		subscribe,
		increment: () => update(n => n + 1),
		decrement: () => update(n => n - 1),
		reset: () => set(0)
	};
}

export const count = createCount();

 

https://svelte.dev/tutorial/custom-stores

 

Stores / Custom stores • Svelte Tutorial

Stores / Custom stores a. Basicsb. Adding datac. Dynamic attributesd. Stylinge. Nested componentsf. HTML tagsg. Making an appa. Assignmentsb. Declarationsc. Statementsd. Updating arrays and objectsa. Declaring propsb. Default valuesc. Spread propsa. If blo

svelte.dev

'Svelte > tutorial' 카테고리의 다른 글

slots  (0) 2022.02.01
classes  (0) 2022.02.01
derived-stores  (0) 2022.02.01
readable-stores  (0) 2022.02.01
auto-subscriptions  (0) 2022.02.01
Comments