alt icon indicating copy to clipboard operation
alt copied to clipboard

Give a warning if bindActions fails to bind?

Open bebraw opened this issue 9 years ago • 6 comments

Let's say you have code like this:

class LaneStore {
  constructor() {
    this.bindActions(LaneActions);
  }
  ...
}

It would be useful if Alt gave warnings for missing bindings during development. Now it's easy to typo a method and miss it given it fails silently.

bebraw avatar Feb 06 '16 08:02 bebraw

I've thought about that but then that means that you'll have to add every method in the actions to the store.

goatslacker avatar Feb 06 '16 20:02 goatslacker

Is there a case where that's a good practice? Can you give a concrete example?

bebraw avatar Feb 06 '16 20:02 bebraw

Not all actions map 1:1 to stores.

UserActions
  userAuthorized
  userUpdated

UserStore
  bindActions(UserActions)

  userUpdated(user) {
    this.setState({ user })
  }


CompanyStore
  bindActions(UserActions)

  userAuthorized() {
    this.setState({ users: this.state.users + 1 })
  }

There's also potentially the case where an action is handled in multiple stores and bindActions is lazily used, we wouldn't want to require the definition of all other actions.

goatslacker avatar Feb 06 '16 21:02 goatslacker

Yeah, great point. What if you could mark actions as strict somehow? Maybe there's a neat way to solve it on definition level. This will make it more verbose, but it will also communicate intent far better.

bebraw avatar Feb 07 '16 03:02 bebraw

I'm cool with that :) .isRequired lol

goatslacker avatar Feb 07 '16 09:02 goatslacker

I'm cool with that :) .isRequired lol

Yeah. I would be happy with a little schema definition. Safer to use, harder to break.

bebraw avatar Feb 07 '16 13:02 bebraw