Git Product home page Git Product logo

feature-redux's People

Contributors

kevinast avatar sylvainlg avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

feature-redux's Issues

redux-persist

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>
  );
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.