-
Notifications
You must be signed in to change notification settings - Fork 2k
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
added deserialization of Date attributes for custom elements #122
Conversation
Thanks for working on this. I think we want to avoid doing any parsing outside of Date.parse. If we really want to add a new type of string date format, I suggest we do it by overriding Date.parse and not inline in attrs.js. WDYT? |
Do you mean to say that attrs.js should only support YYYY/MM/DD formats (as opposed to also . and -)? If so, that's okay by me. That additional logic was in there to paper over inconsistencies w/ how the Date constructor handles the latter two types of strings, anyway. As for Date.parse, do you think we even need to do that, or will new Date(inValue) do? new Date() passes all of the specified tests, and adding Date.parse doesn't seem to add any value, unless of course i'm not testing a case where it would be needed. If just using new Date() is fine, I'll update the PR. |
If we write the Date construction roughly this way: new Date(Date.parse(value) || Date.now()) Then In a separate module we can opt-in to adding new formats to parse without having to ever bother var originalDateParse = Date.parse;
Date.parse = function(s) {
if (/* s is special*/) {
// do special handling on s
else {
return originalDateParse(s);
}
} That way we can decouple Date enhancements from attribute parsing in Toolkit. |
Thanks Scott, makes sense. I'll update the PR for the baseline case and then whip up a quick module impl for additional format support. |
Great, thanks again Brandon. |
Sure thing! Thank you for letting me jump in 👍 |
LGTM |
added deserialization of Date attributes for custom elements
Here's my first pass at adding Date deserialization support to
attrs.js
, as per #119 (tests included). Let me know what you think, and/or if I need to make any additional changes.