kevinast / feature-redux Goto Github PK
View Code? Open in Web Editor NEWfeature-u redux integration
License: MIT License
feature-u redux integration
License: MIT License
Hi Kevin,
First, thanks for the work you're doing here !
I'm trying to get redux-persist working along to feature-redux.
My current approch is to wrap feature-redux to a feature-redux-persist aspect but it is not working. Maybe I miss something in the feature-u architecture which allow me to do this more easily ?
The current code :
import React from 'react'; // peerDependencies
import { extendAspectProperty, createAspect, launchApp } from 'feature-u'; // peerDependency:
import { createReducerAspect } from 'feature-redux';
import { persistStore } from 'redux-persist';
import { PersistGate } from 'redux-persist/integration/react';
import verify from './util/verify';
export const logf = launchApp.diag.logf.newLogger(
'- ***feature-redux-persist*** reduxPersistAspect: '
);
// TODO tests !
export function createPersistedReducerAspect(name = 'reducer') {
// validate parameters
const check = verify.prefix(
'createPersistedReducerAspect() parameter violation: '
);
check(name, 'name is required');
check(typeof name === 'string', 'name must be a string'); // NOTE: didn't want to introduce lodash.isstring dependancy (in the mix of everything else going on in the 1.0.0 upgrade)
const reduxAspect = createReducerAspect(name);
const {
getReduxStore,
getReduxMiddleware,
...restrictedReduxAspect
} = reduxAspect;
return createAspect({
...restrictedReduxAspect,
genesis,
injectRootAppElm: (fassets, curRootAppElm) => {
const persistor = persistStore(reduxAspect.getReduxStore());
return reduxAspect.injectRootAppElm(
fassets,
injectRootAppElm(fassets, curRootAppElm, persistor)
);
},
});
}
function genesis() {
logf(
'genesis() registering two new Aspect properties: getReduxStore() -and- getReduxMiddleware()'
);
// extendAspectProperty('getReduxStore', 'feature-redux-persist'); // Aspect.getReduxStore(): store
// extendAspectProperty('getReduxMiddleware', 'feature-redux-persist'); // Aspect.getReduxMiddleware(): reduxMiddleware
}
function injectRootAppElm(fassets, curRootAppElm, persistor) {
if (curRootAppElm) {
throw new Error(
'***ERROR*** Please register reduxPersistAspect (from feature-router) after feautre-redux aspect ' +
'that inject content in the rootAppElm ...'
);
}
return (
<PersistGate loading={null} persistor={persistor}>
{curRootAppElm}
</PersistGate>
);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.