项目作者: sylvainlg

项目描述 :
feature-u redux persist integration
高级语言: JavaScript
项目地址: git://github.com/sylvainlg/feature-redux-persist.git
创建时间: 2019-12-23T12:00:32Z
项目社区:https://github.com/sylvainlg/feature-redux-persist

开源协议:MIT License

下载


feature-redux-persist

feature-redux-persist is a feature-u integration point to redux-persist. It promotes the persistedReducerAspect (a feature-u plugin) that facilitates redux-persist integration to your features.

feature-redux-persist relies on feature-redux to provide redux integration.

You have to be aware of feature-u philosophy and know about is implementation before reading this documentation

Build Status
Codacy Badge
Codacy Badge
NPM Version Badge

Install

peerDependencies, you should already have these, because this is our integration point (but just in case):

  1. yarn add feature-u
  2. yarn add react
  3. yarn add redux
  4. yarn add react-redux
  5. yarn add feature-redux

the main event:

  1. yarn add feature-redux-persist

Usage

Register

Within your mainline, register the feature-redux reducerAspect (see **1** below) and the feature-redux-persist reducerPersistedAspect (see **2**) to feature-u’s launchApp()

Note **3** : persistedReducerAspect has a required storage configuration parameter (see below)

Note **4** : ORDER MATTER, you have to declare persistedReducerAspect before reducerAspect !

src/app.js

  1. import {launchApp} from 'feature-u';
  2. import {createReducerAspect} from 'feature-redux'; // **1**
  3. import {createPersistedReducerAspect} from 'feature-redux-persist'; // **2**
  4. import AsyncStorage from '@react-native-community/async-storage'; // for react-native
  5. import features from './feature';
  6. export default launchApp({
  7. const persistedReducerAspect = createPersistedReducerAspect(AsyncStorage); // **2** **3**
  8. aspects: [
  9. persistedReducerAspect, // **4**
  10. createReducerAspect(), // **1**
  11. ... other Aspects here
  12. ],
  13. features,
  14. registerRootAppElm(rootAppElm) {
  15. ReactDOM.render(rootAppElm,
  16. getElementById('myAppRoot'));
  17. }
  18. });

Syntax

  1. + createPersistedReducerAspect(storage): Aspect

Parameters

storage

This configuration parameter is required.

You can use every storage in that list: https://github.com/rt2zz/redux-persist#storage-engines

return value

An feature-u Aspect

Promote reducers

/!\ Before reading, you might take a look to https://github.com/KevinAst/feature-redux#usage.

In the state.js, there is some classic redux reducer.

**5** : Enhance basic reducer with persistReducer decorator from redux-persist module.

**6** : Wrap to all thing with slicedReducer from feature-redux module.

Note that you still can use non-persisted reducers with this aspect, you just have to bypass **5**.

  1. import { createFeature } from 'feature-u';
  2. import { slicedReducer } from 'feature-redux';
  3. import { persistReducer } from 'redux-persist';
  4. import AsyncStorage from '@react-native-community/async-storage';
  5. import fname from './feature-name';
  6. import reducer, from './state';
  7. export default createFeature({
  8. name: fname,
  9. enabled: true,
  10. reducer: slicedReducer( // **6**
  11. fname,
  12. persistReducer({ key: fname, storage: AsyncStorage }, reducer) // **5**
  13. ),
  14. // ... snip snip (other aspect properties here)
  15. });