-
Notifications
You must be signed in to change notification settings - Fork 319
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
Discussion: supported serializers out of the box #264
Comments
cc @sorvell and @kevinpschaaf What about offering a JSON type? |
FYI that's pretty much what I did in my example repo. I think it's a good idea instead of detecting usage of Reason being, it'll make it more obvious that it's a serializer, not a type constructor. As you have to explicitly import it and pass it through. |
I'd really go with renaming You can use I prefer LitElement taking a serialization/deserialization path which makes the intention clear without any magic surrounding it. |
If we weren't so close to 1.0, i would agree. It depends on how breaking you feel like being just before 1.0 i suppose. The correct solution to me seems to be to rename If you, @UnrealProgrammer , have a look at the repo i threw up in OP, that implements exactly what you described. a JSON serializer pretty much, which works for both At the very least, we should avoid implementing support for |
It might be useful if the documentation better explained more about the expected form of the "function used for both serialization and deserialization" (see quote below), to prevent the misunderstandings mentioned about the From readme.md:
So my understanding is that When I see examples with edit: I'm wrong, |
I think the concept as a whole is a little too confusing going forward. It isn't an easy thing to document and should be a lot simpler really. We could introduce a set of default serializers and make the docs reflect that, or maybe at least ensure we no longer use |
Marking this as high priority here since the resolution may change API. What exists now is definitely not ideal. What we refer to externally as However, there's also a private Previously we had a special I think perhaps we could leave |
If you want some help, i'm happy to do a PR. We could support Then have |
Fixes #264 Changes `type` to be only a hint to the `converter` option which has the previous `type` functionality, an object with `toAttribute` and `fromAttribute` or just a function which is `fromAttribute`. In addition to the `value` these functions now also get the property's `type`. Also provides a default converter that supports `Boolean`, `String`, `Number`, `Object`, and `Array` out of the box. In addition, numbers and strings now become `null` if their reflected attribute is removed.
* Changes property options to support `converter` Fixes #264 Changes `type` to be only a hint to the `converter` option which has the previous `type` functionality, an object with `toAttribute` and `fromAttribute` or just a function which is `fromAttribute`. In addition to the `value` these functions now also get the property's `type`. Also provides a default converter that supports `Boolean`, `String`, `Number`, `Object`, and `Array` out of the box. In addition, numbers and strings now become `null` if their reflected attribute is removed. * Format * Address review feedback * Update CHANGELOG.md * Clarify documentation about default converter * Format * Fix test to use lowercase attribute names This is working around https://github.com/webcomponents/custom-elements/issues/167. * Fix test on IE * Address review feedback Remove superfluous null checks * Makes reflection more consistent Previously, when an attribute changed as a result of a reflecting property changing, the property was prevented from mutating again as can happen when a custom `converter` is used. Now, the oppose is also true. When a property changes as a result of an attribute changing, the attribute is prevented from mutating again This change helps ensure that when a user calls `setAttribute`, a `converter.toAttribute` does not cause the attribute to immediately mutate. This is unexpected behavior and this change discourages it. * Format. * Address review feedback. * Address review feedback Ensure Object/Array properties respect `undefined` (no change to attribute) and `null` (remove attribute) values.
I recently wrote this blog post about the fact that we don't support
type: Object
andtype: Array
like Polymer did. I also made this repository.This is a thing people assume quite often, even in the recent docs PR.
So I think we need to make a decision before 1.0, one of the following two choices:
Object
andArray
(and possibly require that consumers import them rather than supporting them by default)type
is not a type constructor but rather a type serializer (at this point we can't really renametype
but maybe we could document it very well)I'm happy to PR this if we go with the former.
Right now, people almost always assume because they see examples use
type: Number
,type: String
, etc, they should then usetype: Date
,type: Object
,type: Array
and so on. This won't work as expected, but people rarely bump into this realisation as they pass their data via properties rather than attributes.We do want to keep the core as light as we can, so if we do introduce this, it probably belongs in an extra module we must import ourselves.
cc @justinfagnani
The text was updated successfully, but these errors were encountered: