mantrajs / mantra-sample-blog-app

A sample blog app built with Mantra
http://mantra-sample-blog-app.herokuapp.com/
MIT License
296 stars 104 forks source link

Can i get all actions from context() in component ? #85

Closed lyquocnam closed 8 years ago

lyquocnam commented 8 years ago
const MyComponent = ({context}) => {
  // i want to get actions from this context, this can be ?
 // this.actions can be store all actions or single module.
 const {actions,...} = context();

  return (...)
}

normally i do this:

// pass actions variable from container.
// so i must send from container.
const MyComponent = ({actions}) => {
  // i want to get actions from this context, this can be ?
 // this.actions can be store all actions or single module.
 const {actions,...} = context();

return (...) }

xcv58 commented 8 years ago

Yes, you can: Change container code

export const depsMapper = (context, actions) => ({
  create: actions.posts.create,
  clearErrors: actions.posts.clearErrors,
  context: () => context
});

to

export const depsMapper = (context, actions) => ({
  create: actions.posts.create,
  clearErrors: actions.posts.clearErrors,
  actions,
  context: () => context
});

But you should think why you need this.

lyquocnam commented 8 years ago

yeah i mean we can pass actions to context, do not need use mapper on container. i'm lazy :3 this may be hard ^^

xcv58 commented 8 years ago

It's totally doable.

But context() is for client, actions is designed for individual module. I think it's anti-mantra to do this.