Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Allow pass properties to connected component through the connector #5

Open
samuelsimoes opened this issue Oct 1, 2016 · 4 comments

Comments

@samuelsimoes
Copy link
Collaborator

Today, if we need pass other properties to connected component we need to do something like this:

let connected = FluxoReactConnectStores(People, { people: this.stores.people });
let actions = new PeopleActions(this.stores.people);
return <connected actions={actions} myOtherProp="foo" />;

I think would great have a third argument on the connector to pass other properties to the connected component, like this:

let actions = new PeopleActions(this.stores.people);
return FluxoReactConnectStores(
  People, 
  { people: this.stores.people }, 
  { actions: actions, myOtherProp: "foo" }
);
@sobrinho
Copy link
Member

sobrinho commented Oct 1, 2016

Why would you do that instead of using the react's props?

@samuelsimoes
Copy link
Collaborator Author

To avoid boilerplate as pointed on the example. The third argument will just pass the object to the connected component props.

@sobrinho
Copy link
Member

sobrinho commented Oct 1, 2016

I see no benefits in:

constructor () {
  super(...arguments);

  this.stores = {
    person: new Person
  };

  this.actions = {
    personActions = new PersonActions(this.stores.person)
  };

  this.connectedComponent = Connector(PersonComponent, this.stores, this.actions);
}

render () {
  return <this.connectedComponent />;
}

Over:

constructor () {
  super(...arguments);

  this.stores = {
    person: new Person
  };

  this.actions = {
    personActions = new PersonActions(this.stores.person)
  };

  this.connectedComponent = Connector(PersonComponent, this.stores);
}

render () {
  return <this.connectedComponent {...this.actions} />;
}

The former creates questions about the third argument.

If it does not inject any behavior, why would I use it instead of passing directly to the connected component?

Not implementing raises no questions! :)

@samuelsimoes
Copy link
Collaborator Author

Your exemple could be less verbose and more straightforward using this proposal:

constructor () {
  super(...arguments);

  this.stores = {
    person: new Person
  };

  this.actions = {
    personActions = new PersonActions(this.stores.person)
  };
}

render () {
  return Connector(PersonComponent, this.stores, this.actions);
}

But I also agree with you that people we be on doubt about the third argument… 😞

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants