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

feature request: optional param to pass logic to react-resolver to determine if it should resolve or not? #86

Open
babsonmatt opened this issue Sep 18, 2015 · 3 comments

Comments

@babsonmatt
Copy link

Any thoughts on allowing an optional param to be passed to react-resolver to specify when it should actually resolve? I have a situation where just checking whether or not props has a certain key isn't enough and it'd really come in handy to be able to have some custom logic there.

Thanks!

@ericclemmons
Copy link
Owner

Hah! It sounds like #84 may help. The resolver will bypass any prop that already exists (since it doesn't need resolving).

Can you provide an example?

What I wanted to do in the past was actually having the resolver look at React.PropTypes.foo and checking for the isRequired. If it's required, it always resolves. If it's optional, it would not.

@babsonmatt
Copy link
Author

I use reselect along with redux, and the issue I'm having is the props returned from reselect/redux may have the key for the object I'm trying to load, but the value of it may be something like an empty object, or null, etc. which means react-resolver won't try to load anything... right? So I'd like to be able to specify a custom function to run to determine if something should be loaded or not, ie: obj.length == 0, etc and not just whether or not the key exists in props.

@ericclemmons
Copy link
Owner

Ah interesting!

I did consider changing this behavior to do typeof value === "undefined".

if (!props.hasOwnProperty(name) && !nextState.resolved.hasOwnProperty(name)) {

Would that solve it for you in the interim? The logic is, if the key is undefined, then it should be resolved.

However, null is a valid value for resolution. Similarly, an empty object {} is potentially valid too.

I'm down for coming up with a solution. I just didn't know if undefined can be set on fields that are...well, undefined :D

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

No branches or pull requests

2 participants