Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throws an error when select not returns an object #85

Merged
merged 2 commits into from
Jun 13, 2015

Conversation

rwillrich
Copy link
Contributor

On Connector, verify if select prop, which is a function, returns an
object, and if not, throws an error.

Issue #78

On Connector, verify if `select` prop, which is a function, returns an
object, and if not, throws an error.

Issue reduxjs#78
@@ -59,6 +60,11 @@ export default function createConnector(React) {
selectState({ context, props } = this) {
const state = context.redux.getState();
const slice = props.select(state);

if (!isPlainObject(slice)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Let's use invariant?

import invariant from 'invariant';

// ...

invariant(
  isPlainObject(slice),
  'The return value of `select` prop must be an object. Instead received %s.',
  slice
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@emmenko
Copy link
Contributor

emmenko commented Jun 13, 2015

👍

gaearon added a commit that referenced this pull request Jun 13, 2015
…ject

Throws an error when `select` not returns an object
@gaearon gaearon merged commit e033cac into reduxjs:master Jun 13, 2015
@gaearon
Copy link
Contributor

gaearon commented Jun 13, 2015

Awesome, thank you!

@istarkov
Copy link
Contributor

Mb i'm wrong, but you need to add babel transform to strip invariant message in production like this https://github.com/facebook/react/blob/master/vendor/constants.js

@gaearon
Copy link
Contributor

gaearon commented Jun 14, 2015

I actually don't mind having message in production (it's not that long and we only have very few).

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

Successfully merging this pull request may close these issues.

4 participants