Last active
November 12, 2021 13:03
-
-
Save majo44/aea06861f52e98b483721d5dda26c396 to your computer and use it in GitHub Desktop.
Storeon substore scoped events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>GistRun</title> | |
</head> | |
<body> | |
<script src="index.js" type="module"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStoreon } from 'https://cdn.skypack.dev/storeon'; | |
import { storeonDevtools, storeonLogger } from 'https://cdn.skypack.dev/storeon/devtools'; | |
import { createSubstore } from 'https://cdn.skypack.dev/storeon-substore'; | |
const store = createStoreon([storeonDevtools, storeonLogger]); | |
store.on('test', () => {return { x: 'parent' }}); | |
const aStore = createSubstore(store, 'a', true); | |
aStore.on('test', () => {return { x: 'a' }}); | |
const bStore = createSubstore(aStore, 'b', true); | |
bStore.on('test', () => { return { x: 'b' }}); | |
store.dispatch('test'); | |
aStore.dispatch('test'); | |
bStore.dispatch('test'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment