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

Should we separate Validator.options.valueType into valueTypeOf + valueInstanceOf? #201

Closed
samreid opened this issue Dec 27, 2018 · 1 comment
Assignees

Comments

@samreid
Copy link
Member

samreid commented Dec 27, 2018

From Validator.js:

// TODO: now that we have Validator, do we still want to overload valueType?  Or split it up into:
// TODO: {valueTypeOf: 'boolean'} vs {valueInstanceOf: 'Vector2'}
if ( options.valueType ) {
  const valueType = options.valueType;
  if ( typeof valueType === 'string' ) { // primitive type
    assert( typeof value === valueType, 'value should have typeof ' + valueType + ', value=' + value );
  }
  else if ( typeof valueType === 'function' ) { // constructor
    assert( value instanceof valueType, 'value should be instanceof ' + valueType.name + ', value=' + value );
  }
}

Related to #189.

Client code would change from:

new Property(1,{valueType: 'number'});
new Property(myVector,{valueType: Vector2});

to

new Property(1,{valueTypeOf: 'number'});
new Property(myVector,{valueInstanceOf: Vector2});

Self assigning to consider before bringing it to the dev team.

@samreid samreid self-assigned this Dec 27, 2018
samreid added a commit that referenced this issue Dec 27, 2018
@samreid
Copy link
Member Author

samreid commented Apr 3, 2019

While it would be possible to simplify the implementation, having a simple and nice API is more important. The TODOs have been removed. Closing.

@samreid samreid closed this as completed Apr 3, 2019
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

1 participant