Skip to content

Instantly share code, notes, and snippets.

@majo44
Last active November 12, 2021 13:03
Show Gist options
  • Save majo44/aea06861f52e98b483721d5dda26c396 to your computer and use it in GitHub Desktop.
Save majo44/aea06861f52e98b483721d5dda26c396 to your computer and use it in GitHub Desktop.
Storeon substore scoped events
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
</head>
<body>
<script src="index.js" type="module"></script>
</body>
</html>
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