Comments (8)
Are your enums simple strings or implemented as an actual "type"? Do you have some sample code to illustrate? If your enums are implemented as just strings, then they wouldn't appear as a proper type other than the "string" type.
xtypejs supports Instance Types, which would allow you to validate your enum, as long as it's implemented as a proper type (for instance, a WeekDay type representing the days of the week).
If you can provide some sample code of your current implementation, I could try to provide some code examples of an Instance Type based solution.
from xtypejs.
We have both instance types and string types.
The instance types are obviously supported as you mentioned. My request was for string types:
var STATES = {
ACCEPTED: 'ACCEPTED',
REJECTED: 'REJECTED'
};
var objectToBeValidated = {
state: STATES.ACCEPTED
};
Now I want to do something like:
xtypejs.isEnum(objectToBeValidated.state, STATES)
I am not sure how this would work with .type
since it really is a string as you pointed out.
from xtypejs.
Can registerTypes handle this? It looks close, but you'd probably need for it to accept a custom function that can test for whether an arbitrary thing passed in meets the criteria for the new type.
Also, you would probably need to allocate a higher-number space for custom-type ID numbers to live in.
from xtypejs.
A registerTypes approach would have to be implemented in a way that keeps the new type completely compatible with any other built-in or previously registered types, which might be possible. Definitely worth exploring ..will look into it.
from xtypejs.
After exploring the registerTypes approach to this, I'm going to go ahead and implement it, after which you can give it a try for your use case and provide feedback based on that.
from xtypejs.
Woohoo. Thanks for the quick turnaround. Looking forward to using this.
On Thu, Jul 2, 2015, 4:45 PM lucono [email protected] wrote:
After exploring the registerTypes approach to this, I'm going to go ahead
and implement it, after which you can give it a try for your use case and
provide feedback based on that.—
Reply to this email directly or view it on GitHub
#1 (comment).
from xtypejs.
Created #2 for the implementation of the custom validation feature.
from xtypejs.
Regarding enums:
xtypejs supports Instance Types, which are able to validate Enums implemented as actual enum types. More in this comment.
Regarding arbitrary custom validation:
This would support arbitrary string and/or any other type of arbitrary validation logic, completely integrated and compatible with all other xtypejs custom and non-custom (built-in) types.
See: Arbitrary Custom Validation Support (issue #2) - available in next release of xtypejs.
from xtypejs.
Related Issues (7)
- Add not, any, all, some, none interface variants of xtype.is HOT 3
- Checking values with compact representation does not work HOT 1
- Support for arbitrary custom-validated types HOT 1
- default to descriptive names tab on xtype.js.org HOT 1
- Break out non-core functionality into optional add-on modules HOT 1
- Introduce additional name schemes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xtypejs.