Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NGRX implementation #81

Open
distolma opened this issue Jan 30, 2018 · 0 comments
Open

NGRX implementation #81

distolma opened this issue Jan 30, 2018 · 0 comments

Comments

@distolma
Copy link

distolma commented Jan 30, 2018

Do you have implementation of electron-redux for ngrx?

I try to implement this middleware for ngrx metaReducers, but i have some problems with it.

const isLocalAction = ({ meta }: Action) => (meta && meta.scope && meta.scope === 'local');

const isServiceAction = ({ type }: Action) => type.substr(0, 5) === '@ngrx';

const isFSA = (action: Action) => Object.keys(action).every((key) => [
  'type',
  'payload',
  'error',
  'meta',
].indexOf(key) > -1);

export function electronRedux(reducer: ActionReducer<any>): ActionReducer<any> {
  return function(state, action: Action) {
    if (isServiceAction(action)) {
      return reducer(state, action);
    }

    if (!isFSA(action)) {
      return reducer(state, action);
    }

    if (isLocalAction(action)) {
      return reducer(state, action);
    }

    electron.ipcRenderer.send('redux-action', action);
    return state;
  };
}

metaReducer should always return the store. I can`t prevent action like in redux middlewares.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant