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

.set and .setOf #191

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

.set and .setOf #191

wants to merge 1 commit into from

Conversation

Pimm
Copy link

@Pimm Pimm commented Jun 5, 2018

An implementation for .set and .setOf. Please hit me with your feedback, thoughts, and ideas.

I can implement .map and .mapOf in this PR as well.

@ljharb mentioned that instanceof Set does not work everywhere. Perhaps that has to be fixed.

Copy link
Collaborator

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

What about Map?

function createSetTypeChecker(expectedType) {
function validate(props, propName, componentName, location, propFullName, secret) {
var propValue = props[propName];
if (!(propValue instanceof Set)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

indeed, this should module-level-cache the getter for Set.prototype.size, call-bind it, and invoke it here.

return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside setOf.');
}
var propValue = props[propName];
if (!(propValue instanceof Set)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

also here

@@ -505,6 +553,8 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
return 'date';
} else if (propValue instanceof RegExp) {
return 'regexp';
} else if (propValue instanceof Set) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

and here

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

Successfully merging this pull request may close these issues.

None yet

3 participants