react-immutable-js-store
React wrapper around immutable-js-store.
Installation
npm install react-immutable-js-store
Api
connect({ actions, component, store, subscriptions })
Connects a React component to an immutable-js-store
store.
This function accepts the following named parameters:
Property | Type | Required? | Description |
---|---|---|---|
actions | Object | Expose updates to the store to the connected component | |
component | Component | ✓ | Decorated component to be connected to the store |
store | ImmutableStore | ✓ | Store |
subscriptions | Object | Expose the current state of the store to the connected component |
The subscriptions object can contain 2 types of values:
- Array values will be auto-subscribed and the corresponding property will be updated when the subscription is notified.
- Keys with Function values will be called each time the store changes; a single parameter (the current state) will be passed.
Example
// Initialize store with default dataconst store = items: newItemText: '' // Expose the current state of the store to the "connected" component.// Keys with Array values will be subscribed and have their props auto-updated.// Keys with Function values will be called each time the store changes.const subscriptions = store store newItemText: 'newItemText' items: 'items' // Expose updates to the store to the "connected" componentconst actions = {} {} { store } { store } {} {} // Dumb component to be connected to the ImmutableStore. static propTypes = addItem: PropTypesfuncisRequired hasNext: PropTypesboolisRequired hasPrevious: PropTypesboolisRequired newItemText: PropTypesstringisRequired items: PropTypesisRequired removeItemAt: PropTypesfuncisRequired setNewItemText: PropTypesfuncisRequired stepBack: PropTypesfuncisRequired stepForward: PropTypesfuncisRequired toggleAll: PropTypesfuncisRequired toggleItemAt: PropTypesfuncisRequired ; { // ... } // Connect the actions subscriptions storeApplication