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

combineReducers #66

Open
KovalevAnton opened this issue Jan 23, 2018 · 3 comments
Open

combineReducers #66

KovalevAnton opened this issue Jan 23, 2018 · 3 comments
Labels

Comments

@KovalevAnton
Copy link

Hello! Tell me, please, how i can join reducers, like "combineReducers" in Redux?

@developit
Copy link
Owner

Hmm - do you have an example of where this is needed?

function combineReducers(...fns) {
  return (...args) => Object.assign(...fns.map( fn => fn(...args) );
}

@aprilmintacpineda
Copy link

aprilmintacpineda commented Jun 12, 2018

I think no need for a combine reducers.

/ root
| -- actions
|     | -- someActions.js // returns an object that handles **some actions**
|     | -- anotherActions.js // returns an object that handles **another actions**
|     ` -- index.js // returns all the actions spread on an object
`-- store.js

someActions.js

export default {
  one (state) {
    // do what?
  },
  two (state) {
    // do what?
  }
};

anotherActions.js

export default {
  one (state) {
    // do what?
  },
  two (state) {
    // do what?
  }
};

index.js

import someActions from './someActions';
import anotherActions from './anotherActions';

export default {
  ...someActions,
  ...anotherActions
};

store.js

import createStore from 'unistore';
import actions from './actions';

const store = createStore({
  // what?
});

const actions = store => ({ ...actions });

export { actions };
export default store;

now you can access them.

import { Provider, connect } from 'unistore/preact';
import store, { actions } from './store';

const App = connect('count', actions)(
  ({ count, increment }) => (
    <div>
      <p>Count: {count}</p>
      <button onClick={increment}>Increment</button>
    </div>
  )
)

export default () => (
  <Provider store={store}>
    <App />
  </Provider>
)

@dy
Copy link

dy commented Apr 3, 2019

@aprilmintacpineda in this case we connect all our app actions into out component.

Sometimes we'd like to have a subset of actions like

connect(props, {...auth, ...catalog})(props => (...))

because not every screen/component needs all set of actions of our app.
If #136 was implemented, that'd be enough to

props => {
let {login, logout} = useActions(auth)
let {fetch} = useActions(catalog)
}

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

No branches or pull requests

4 participants