-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
RFC: Pass through attribute meta data to related Transform #1
RFC: Pass through attribute meta data to related Transform #1
Conversation
+1 |
I like this a lot and seems good. @igorT thoughts? |
👍 |
This was approved for implementation at the core team meeting. I'll be the champion, but if someone wants to be the implementer let me know. You might get to it faster. :) |
First RFC and over a year later! There is always hope! 👍 |
@fivetanley should this be merged in? Or is that after implementation? |
Let's wait til after implementation. Seems easier to track. |
Added via 85ef99c |
Add drain, and link to WIP implementations.
Adding proper @ember-data package name where missing
Would love comments! cc @igorT, @fivetanley
(RFC content pasted in by @machty)
Summary
For Ember Data. Pass through attribute meta data, which includes
parentType
,options
,name
, etc.,to the transform associated with that attribute. This will allow provide the following function signiture updates to
DS.Transform
:transform.serialize(deserialized, attributeMeta)
transform.deserialize(serialized, attributeMeta)
Motivation
The main use case is to be able to configure the transform
on a per-model basis making more DRY code. So the transform can be aware of type and options on
DS.attr
canbe useful to configure the transform for DRY use.
Detailed design
Implementing
The change will most likely start in
eachTransformedAttribute
, which gets the attributes for that instance viaget(this, 'attributes')
. In theforEach
thename
will be used to get the specific attribute, e.g.The next change will be in
applyTransforms
, where theattributeMeta
parameter is added and passed totransform.deserialize
as the second argument.You also have to handle the serialization part in
serializeAttribute
, where you pass through theattribute
parameter totransform.serialize
.Using
A convoluted example:
Drawbacks
Extra API surface area, although not much. This could also potentially introduce tight coupling between models and transforms if used improperly, e.g. not returning a default value if using type checking.
Alternatives
Unresolved questions
Does the whole meta object need to be passed, or do we selectively pass in only the useful properties? Like
options
andparentType
andname
..