mantrajs / mantra-sample-blog-app

A sample blog app built with Mantra

Home Page: http://mantra-sample-blog-app.herokuapp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

lyquocnam opened this issue · comments

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 (...)
}

commented

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.

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

commented

It's totally doable.

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