Created
October 27, 2017 19:36
-
-
Save melikhov-dev/7d3cda1c8afd53842e8d433458e9af8a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const controller = Controller({ | |
state: { | |
items: [] | |
}, | |
signals: { | |
itemAdded: push(state`items`, props`item`) | |
} | |
}) | |
// Компоненты | |
const Items = connect({ | |
items: state`items`, | |
itemAdded: signal`itemAdded` | |
}, | |
function ItemsComponent ({items, itemAdded}) { | |
return ( | |
<div> | |
<ul> | |
{items.map((item) => <li>{item}</li>)} | |
</ul> | |
<button onClick={() => itemAdded({item: 'foo'})}> | |
Add foo | |
</button> | |
</div> | |
) | |
} | |
) | |
// Передаём состояние в компоненты | |
render(( | |
<Container controller={controller}> | |
<Items /> | |
</Container> | |
), document.querySelector('#app')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment