Skip to content
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

Allow Store#pushPayload to delete records in store #1945

Closed
nixpulvis opened this issue May 15, 2014 · 13 comments
Closed

Allow Store#pushPayload to delete records in store #1945

nixpulvis opened this issue May 15, 2014 · 13 comments

Comments

@nixpulvis
Copy link

It would be nice to allow the deletion of records via a specially formatted message passed to Store#pushPayload. This would allow api designers to send a message for a record indicating it was deleted.

The use case for this for me at the moment is for integration with WebSockets. I'm building an adapter which calls pushPayload when it receives a message.

var _this = this;
var socket = new WebSocket('ws://' + window.location.host + '/api/v1/events/doors');
socket.onmessage = function(event) {
  _this.get('store').pushPayload('door', JSON.parse(event.data));
}

Maybe sending a message like

{
  "post": { "id": "1" },
  "_method": "delete"
}

Allowing this to also remove records would be awesome.

@Bestra
Copy link

Bestra commented May 16, 2014

We've run into something similar on a current project. We're using an EventSource to push data to a client and we include a flag similar to the _method you've suggested. We just branch based on the type of method. If it's 'add' we pass the payload along to pushPayload. If it's delete we'll call deleteRecord with the id in the payload. To me it seems like in the more general case you could do the same sort of logic in the adapter rather than keeping it in pushPayload.

@nixpulvis
Copy link
Author

Yea, I'm implementing something like that with Websockets. Seems like a very common pattern, might be nice to support it.

@igorT
Copy link
Member

igorT commented May 28, 2014

@wycats any thoughts?

@nathanpalmer
Copy link

We do something similar but include a type along with our payload.

  {
    "id": "123",
    "type": "post",
    "method": "create",
    "data": {}
  }

or

  {
    "id": "123",
    "type": "post",
    "method": "delete"
  }

So in the case of create/update we can use pushPayload and delete we can run a deleteRecord on it. I could definitely see the benefit of just using pushPayload and avoid some of that code we have. I assume syncing front and backend data is a somewhat common practice.

@pangratz
Copy link
Member

I think this should definitely be supported by ember-data, but it might be a good idea to go through the process of RFC so the specific API can be fleshed out.

Closing this in favor of being discussed further at https://github.com/emberjs/rfcs

@nixpulvis
Copy link
Author

This is how tickets get lost.

@pangratz
Copy link
Member

@nixpulvis you're right! Reopening and will close once such a PR exists.

@pangratz pangratz reopened this Feb 12, 2016
@stevesims
Copy link

This would indeed be very useful.
+1 from me!

@Asherlc
Copy link

Asherlc commented May 15, 2016

Would something like this need to make it's way in to JSON API first?

@kbullaughey
Copy link

+1, I could use this too. Although I'm still stuck on the ActiveModelAdapter so it would be nice if it has across-the board support.

@pangratz
Copy link
Member

@Asherlc, yep. Having such a functionality defined in JSON-API at first would definitely help this issue being moved forward.

json-api/json-api#795 (comment) is a relevant comment.

@runspired
Copy link
Contributor

emberjs/rfcs#854 adds operations to the cache, all we need now is an addition to it for deletions :)

@runspired
Copy link
Contributor

closing in favor of the above RFC adding it now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants