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

Usage with React propTypes #96

Closed
Zalastax opened this issue Sep 26, 2015 · 5 comments
Closed

Usage with React propTypes #96

Zalastax opened this issue Sep 26, 2015 · 5 comments

Comments

@Zalastax
Copy link

I would like to use propTypes (or some other type validation) together with cortex. Is there any way to do that currently without having to also specify __values?

@mquan
Copy link
Owner

mquan commented Sep 27, 2015

you get to the value by either getValue() or val(), you shouldn't access __value

@Zalastax
Copy link
Author

But then every propType will end in React.PropType.func which doesn't convey any information about the property. Look at http://facebook.github.io/react/docs/reusable-components.html and https://github.com/HurricaneJames/react-immutable-proptypes

@mquan
Copy link
Owner

mquan commented Sep 27, 2015

Have you looked into custom type validation? Let me know if the following is what you're looking for.

cortexTypeOf(cortex, propType) {
  // this may be a little simplistic and need to be improved.
  // you can also create a bunch of helpers that are built on top of this function.
  // like cortexType.isNumber, cortexType.isString, etc.
  // ultimately this could become a lib similar to react-immutable-proptypes but for cortex. 
  return typeof cortex.getValue() === propType;
}
myCortexProp: function(props, propName, componentName) {
  if (!cortexTypeOf(props[propName], yourPropType) {
   return new Error('Validation failed!');
  }
}

@Zalastax
Copy link
Author

Yes, this is what I need!
The main problematic areas are arrays and objects, but it shouldn't be too hard to copy the implementation from react-immutable-proptypes. I don't think I'll have time to implement this in the near future but I'll see what I can do since cortex looks great otherwise.

@mquan
Copy link
Owner

mquan commented Sep 28, 2015

I'm closing this since there's a solution and it isn't a core problem in cortex

@mquan mquan closed this as completed Sep 28, 2015
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