-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[FEATURE ds-pushpayload-return] Change pushPayload
to return a value.
#4110
Conversation
a0f6211
to
ce4a428
Compare
@bmac Done. I wasn't sure what to do about the documentation since it just adds a return. I can remove that for now and add it back if/when this feature flag is removed. Not sure which would be more desirable. |
ce4a428
to
490e03c
Compare
pushPayload
to return a value.pushPayload
to return a value.
Hi @workmanw we discussed this in the Ember Data meeting today and everyone present was on board with merging this behind a feature flag. Do you mind rebasing this pr so it can be merged? |
490e03c
to
f428be8
Compare
…he "pushed value". Either a record or array of records.
f428be8
to
1097530
Compare
@bmac Awesome. I've rebased this, and removed the API docs as we discussed on slack. Let me know if there are any further changes I can make. Thank you 👍 |
[FEATURE ds-pushpayload-return] Change `pushPayload` to return a value.
@workmanw This is an awesome adjustment! ⛵ |
@@ -178,7 +179,11 @@ const JSONAPISerializer = JSONSerializer.extend({ | |||
*/ | |||
pushPayload(store, payload) { | |||
let normalizedPayload = this._normalizeDocumentHelper(payload); | |||
store.push(normalizedPayload); | |||
if (isEnabled('ds-pushpayload-return')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do this in the store instead, and lets have the serializer return normalized json payload
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igorT I'm not 100% sure I follow.
Currently store.pushPayload
just looks up the associated serializer and invokes serializer.pushPayload
. The serializers uniquely handle their normalize operations and then callback to the store (store.push
).
So with all that said, I read your comment as saying, "Can we move this feature check into the store only?" In order to do that, I think you would 1) have to always just return the store.push
result, or 2) create a new API mechanism for the store to ask the serializer to normalize the payload so the pushPayload` action didn't have to pass through the serializer (which I think is what maybe you were hinting at).
I'm happy to make additional changes or spend additional time continue to improve this feature. Please also tell me if I misunderstood your request. Let me know what you'd like me to do.
Has there been any discussion on this? I would definitely like to see it enabled and I understand if there are more factors at play, but I don't want it to be forgotten. |
Has this change only been made to the EDIT: reviewed the PR, and it seems it is implemented for ``RESTAdapter`. I suppose I have to enable canary mode? |
Hey @workmanw, sorry for the long overdue response. So at the moment it wouldn't hurt if we return the pushed records from But once we return the pushed records from I can imagine apps using WebSockets make heavy use of I totally agree with the points you raised in #3576 (comment) regarding this being an inconsistency between Long story short, I've created RFC#161 to get a discussion going, in which direction we want to go so all use cases are supported. I would love to hear your input on this. |
Was this removed in the latest master? My pushPayload calls don't seem to return anything anymore. |
What happened to this feature flag? |
Seems like it is still used though: https://github.com/emberjs/data/search?utf8=%E2%9C%93&q=ds-pushpayload-return |
I was checking Thanks. |
Hey! Is there any plan when this option be available by default? |
I'm confused - this was merged but doesn't seem to work?
https://github.com/emberjs/data/blob/master/config/features.json#L3 Thanks! |
@allthesignals Just to be sure, are you using a canary build of ember-data ? |
is this feature added? I can not see anything returned from pushPayload method. |
@bbansalWolfPack It's not added, unfortunately. The next steps are:
|
Here is the solution for that: https://www.emberjs.com/blog/2018/04/13/ember-3-1-released.html#toc_feature-flag-code-ds-pushpayload-return-code-4-of-4 |
For anyone who is looking for a solution that allows you to pushPayload with different model types you can do this: // import { singularize } from 'ember-inflector';
store.pushPayload(response);
return response.data.map(m => store.peekRecord(singularize(m.type), m.id)) assuming your response is JSON:API and has a data object with an array of models 👍 |
@runspired so that wouldn't work for me because I'm working with a mixed type array coming back across the wire. (I swear I'm not trying to be difficult 😂) Do you see any obvious limitations to this hybrid approach:
it seems to work fine for the toy(ish) example that we have right now. |
|
So if I pare it down to this:
I get an error: I'm assuming it's the As for per-type serializers, that isn't necessary. This format also works:
|
@mansona you do realize that For instance, if your only issue was needing to singularize types, this would work best:
as a side-note, we're working to eliminate the need to singularize and dasherize types. The only requirement will be that the format matches the modelName on disk and is consistent (e.g. if you give ember-data a singular camelCase type, then later give it the dasherized plural type that would be an error). |
so this would be fine but you also need to do that all the way down the stack and singularise the includes and all the relationships in each of the objects 🤔 another naive implementation that extends your idea would be this:
but again we have a problem because the API is returning dasherized attributes and I'm assuming the normaliser is the one who's job it is to fix that? 🤔 I could de-dasherize in this loop but I think we're getting into the realm of "a bit much" to be recommending 😞 thoughts? |
You are narrowing in on what folks should be doing :) Write a functional normalizer that works for you, and aligns your payloads to json-api with singularized, dasherized types and camelCase members.
Then you could write a nice application serializer like this:
And finally, write your push util like this for ad-hoc requests and web-socket side-channels:
Finally, once your API uses the same format as ember-data, you simply drop this normalization step in your serializer and for pushPayload you use |
Changing
store.pushPayload
andserializer.pushPayload
to return the "pushed value". Either a record or array of records.You can see by the diff, this is actually a pretty trivial change and it would greatly benefit those of us using
pushPayload
. The only risk of breakage is if someone has overriddenpushPayload
in their serializer, the value may not be returned.Addresses: #3576