path

path is a concept of a stringified accessor location on an object. For example, take the object below.

const object = {
  foo: { 
    bar: 
      [ 
        { baz: 1 },
      ],
    },
  },
};

Say you want to get the value from the "baz" key nested within the object. You would typically just do this:

object.foo.bar[0].baz // 1

In coflux, path describes that location. It is the exact same as the general path to access a value, except wrapped in a string. coflux uses that string to know where state is you want at any given time. Here's an example in coflux:

const state = {
  foo: { bar: 1 },
};

ReactDOM.render(
  <Provider state={state}>
    <Component />
  </Provider>
  , domNode
);

function Component(props) {
  return (
    <div>
      {`Counter value: ${props.bar}`}
    </div>
}

wrap(Component, {
  mapStateToProps() {
    return {
      bar: 'foo.bar',  // path describe state location
    };
  },
});

That should give you a taste of path and above gives you a brief introduction to the wrap API. The next page will explain the wrap API.

results matching ""

    No results matching ""