reyesoft / ngx-jsonapi

JSON API client library for Angular 5+ 👌 :: Production Ready 🚀
https://ngx-jsonapi.reyesoft.com/
MIT License
101 stars 52 forks source link

Add resource to collection without saving #110

Closed dustinblanchard closed 6 years ago

dustinblanchard commented 6 years ago

I am trying to use this along with webhooks in my application. For instance, when I have a new notification, my Angular application receives the JSON of the new notification. I need to be able to do two things:

Is there a way to extend .new() to allow me to

  1. create the resource using the JSON from my webhook.
  2. verify no duplicate resource already exists in the collection (match id or the full object)
  3. add the resource to the collection (updating the observable in my controller)
pablorsk commented 6 years ago

V2.0

I need to make sure this resource does not already exist in the collection. If it does not already exist in the collection, I need a way to add it to the collection without saving it to the API (since it came from the server in the first place).

colleciton.replaceOrAdd(resource); // resource is Resource type

create the resource using the JSON from my webhook.

resource = service.new();
resource.fill(data);