redux-fractal
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -106,5 +106,6 @@ 'use strict'; | ||
value: function componentWillUnmount() { | ||
var persist = typeof Config.persist === 'function' ? Config.persist(this.props) : Config.persist; | ||
this.context.store.dispatch({ | ||
type: UIActions.UNMOUNT_COMPONENT, | ||
payload: { persist: Config.persist }, | ||
payload: { persist: persist }, | ||
meta: { triggerComponentKey: this.key } | ||
@@ -111,0 +112,0 @@ }); |
{ | ||
"name": "redux-fractal", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A local component state management library using Redux", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -331,2 +331,31 @@ # redux-fractal | ||
``` | ||
If there are multiple instance of MyComponent, using `persist` as shown above will persist the state of ALL instances. | ||
You can have fine grained control over which component instances get persisted and which do not | ||
by defining `persist` as a function receiving the component props. | ||
```js | ||
const HOC = local({ | ||
key: (props) => props.itemId, | ||
createStore: (props, existingState) => { | ||
return createStore( | ||
rootReducer, | ||
existingState || { filter: true } | ||
); | ||
}, | ||
// Any logic depending on props here to decide if the component state should be persisted | ||
persist: (props) => props.keepState | ||
}); | ||
const ConnectedItem = HOC(Item); | ||
const App = (props) => { | ||
return ( | ||
<div> | ||
<ConnectedItem itemId={'a'} keepState={true} /> | ||
<ConnectedItem itemId={'b'} keepState={false} /> | ||
</div> | ||
); | ||
} | ||
``` | ||
In the above example only the state of component with itemId 'a' will be kept in the global | ||
state after the component unmounts. | ||
### I need to read a component's state somewhere else: eg in thunk action creators, sagas, in `mapStateToProps` | ||
@@ -333,0 +362,0 @@ All the local components state is available at `state.local[key]` where `key` is the key for the component |
@@ -59,5 +59,7 @@ import React from 'react'; | ||
componentWillUnmount() { | ||
const persist = typeof Config.persist === 'function' ? | ||
Config.persist(this.props) : Config.persist; | ||
this.context.store.dispatch({ | ||
type: UIActions.UNMOUNT_COMPONENT, | ||
payload: { persist: Config.persist }, | ||
payload: { persist: persist }, | ||
meta: { triggerComponentKey: this.key } | ||
@@ -64,0 +66,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39263
408
368