Code Monkey home page Code Monkey logo

Comments (4)

xcv58 avatar xcv58 commented on August 17, 2024

The clearErrors come from this file: https://github.com/mantrajs/mantra-sample-blog-app/blob/master/client/modules/core/actions/posts.js

This line will combine actions and context together.

from mantra-sample-blog-app.

norain2050 avatar norain2050 commented on August 17, 2024

@xcv58 I know that actions and context is in the container,but the clearnErrors in the https://github.com/mantrajs/mantra-sample-blog-app/blob/master/client/modules/core/actions/posts.js have the module namespace: https://github.com/mantrajs/mantra-sample-blog-app/blob/master/client/modules/core/actions/index.js

import posts from './posts';

export default {
  posts
};

And in Mantra-core API.js:

  _bindContext(_actions) {
    const actions = {};
    for (let key in _actions) {
      if (_actions.hasOwnProperty(key)) {
        const actionMap = _actions[key];
        const newActionMap = {};
        for (let actionName in actionMap) {
          if (actionMap.hasOwnProperty(actionName)) {
            newActionMap[actionName] =
              actionMap[actionName].bind(null, this.context);
          }
        }
        actions[key] = newActionMap;
      }
    }

    return actions;
  }

The key is the "module namespace".So, I will use it by "acions.posts.clearErrors", like the "Actions with the same export name will be overwritten #10":"Modules should be independent of each other so as action methods".

At the same time, this container :newpost.js have the depsMapper functions whose argument is (context, actions),look here:

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

It ues the "create" and "clearErrors" in the actions by the "module namespace:posts".

Why ?

from mantra-sample-blog-app.

xcv58 avatar xcv58 commented on August 17, 2024

@norain2050 You are misunderstanding how compose get props. The compose function's first argument is props. The props is whatever props the parent pass to the container, plus the result of depsMapper.

The idea is that you don't need to pass all actions to the component, you can only pass necessary action(s) to your component. The depsMapper will do this for you and eliminate the long namespace.

You can take a look at my implementation: https://github.com/ops-class/test161-web-ui/blob/master/app/src/client/modules/core/containers/submissionlist.js#L4-L45

from mantra-sample-blog-app.

norain2050 avatar norain2050 commented on August 17, 2024

@xcv58 Thank you very much.Now, I had understanded it.

from mantra-sample-blog-app.

Related Issues (20)

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.