有效负载在服务层中无法正常运行

时间:2019-04-02 10:15:51

标签: reactjs redux react-redux

问题: 我正在使用react和redux逻辑开发应用程序,从组件中我要求采取行动。通过动作,它触发了逻辑。在这里,我提供了如何组织逻辑。

createLogic({
    type: NodeHeirarchyTypes.NODE_HEIRARCHY_ADD,
    latest: true,
    //debounce: 2000,

    process({ MockHTTPClient, getState, action }, dispatch, done) {
      //console.log(action.payload.code, action.payload.name);
      debugger;
      console.log("Calling NODE_HEIRARCHY_ADD ");
      var node = {};
      node.code = action.payload.code;
      node.name = action.payload.name;

      node.nodeType = action.payload.nodeType;
      node.order = action.payload.order;

      console.log("node object is", node);

      dispatch(NodeHeirarchyActions.queryStart());

      //To load the screen
      let HTTPClient;

      if (MockHTTPClient) {
        HTTPClient = MockHTTPClient;
        console.log("Hi I am mock");
      } else {
        HTTPClient = API;
      }
      // debugger;

      //dispatch(NodeHeirarchyActions.addHeirarchySuccess("node"));

      setTimeout(() => {
        dispatch(NodeHeirarchyActions.addHeirarchySuccess("node"));
        done();
      }, 2000);

      return;

      HTTPClient.Post(endPoints.NODE_HEIRARCHY_CREATION, action.payload)
        .then(resp => resp.data)
        .then(data => dispatch(NodeHeirarchyActions.addHeirarchySuccess(data)))
        .then(data => dispatch(NodeHeirarchyActions.queryEnd(data)))
        .catch(err => {
          var errorMessage =
            (err.response && err.response.data && err.response.data.message) ||
            err.message ||
            "Node Heirarchy Edit Failed";
          console.error(err);
          if (err && err.code == "ECONNABORTED") {
            errorMessage = "Please check your internet connection.";
          }
          dispatch(
            NodeHeirarchyActions.addFailed({
              title: "Error",
              message: errorMessage
            })
          );
          dispatch(NodeHeirarchyActions.queryEnd(err));
          done();
        })
        .then(() => done());
    }
  }),

这是我的动作。

 handleSubmit = event => {

    debugger;
    this.props.addHeirarchy({
      code: this.state.code,
      nodeType: this.state.nodeType,
      name: this.state.name,

      order: this.state.order
    });

  };

当我尝试直接分配一个值时,它没有使用有效负载,而是正确地获取了数据

例如:

      node.code = "123";
      node.name = "Jack";

如何创建有效的有效载荷?

0 个答案:

没有答案