beauby / jsonapi-datastore

JavaScript client-side JSON API data handling made easy.
MIT License
195 stars 40 forks source link

Removing objects from datastore #28

Open skinnerdev opened 8 years ago

skinnerdev commented 8 years ago

I saw issue #26 and realized we had this logic on a fork of this project. Here is the code we've implemented to provide this functionality.

I've added a property to data store models that holds information about other models that reference it. This property is used during delete to assist with the complete removal of this object from the store. Any time a model with references is added to the store, we touch the references and "inform" them that they have been referenced.

The delete process uses the data in the associations array to find other objects in the store that reference the model to be deleted. If the deleted model is referenced with a hasMany relationship, the model to be deleted is removed from the referencing model's relationship array. If the reference is a hasOne/belongsTo relationship, the referencing model's relationship is given a new blank datastore model with only the _type property set.

beauby commented 8 years ago

Thanks a lot for this, looks solid to me. Will review it ASAP.

Cheers,

On Thursday, 10 March 2016, David Skinner notifications@github.com wrote:

I saw issue #26 https://github.com/beauby/jsonapi-datastore/issues/26 and realized we had this logic on a fork of this project. Here is the code we've implemented to provide this functionality.

I've added a property to data store models that holds information about other models that reference it. This property is used during delete to assist with the complete removal of this object from the store. Any time a model with references is added to the store, we touch the references and "inform" them that they have been referenced.

The delete process uses the data in the associations array to find other objects in the store that reference the model to be deleted. If the deleted model is referenced with a hasMany relationship, the model to be deleted is removed from the referencing model's relationship array. If the reference is a hasOne/belongsTo relationship, the referencing model's relationship is

given a new blank datastore model with only the _type property set.

You can view, comment on, or merge this pull request online at:

https://github.com/beauby/jsonapi-datastore/pull/28 Commit Summary

  • Added a property to datastore models that holds information about other models that reference it. This property is used during delete to assist with the complete removal of this object from the store.

File Changes

Patch Links:

— Reply to this email directly or view it on GitHub https://github.com/beauby/jsonapi-datastore/pull/28.

Lucas Hosseini lucas.hosseini@gmail.com

beauby commented 8 years ago

Awesome, this feature is clearly a must! A few minor remarks, but I'd love to merge that ASAP.

skinnerdev commented 8 years ago

I've pushed up the changes as per our conversation thus far. On the property name issue, I think _dependents is fairly descriptive. Though if someone has a better idea for a name I'd be happy to change it.

beauby commented 8 years ago

Great, thanks! _dependents seems good to me. Last thing needed would be one or two tests. I could probably write some tomorrow if you don't have time.

skinnerdev commented 8 years ago

The original work I had done on this is on another computer with my testing environment set up. I don't have a testing setup on this machine. If I have some time next time I am by it, I'll try and write some. Though might be a few days... :\

beauby commented 8 years ago

No worries, I can do it. Note that running the tests should just be a matter of

$ npm install
$ gulp test
skinnerdev commented 8 years ago

Thanks for the reminder! I had some extra time and setup the tests on this machine. I went and added a test and discovered a few tweaks that would help keep it clean. Let me know if there are any adjustments needed. :)

beauby commented 8 years ago

Nice, I think we're really close now, a tiny bit of cleanup and we should be good to merge!

skinnerdev commented 8 years ago

Added the _addDependence and _removeDependence.

beauby commented 8 years ago

Awesome, will review ASAP!

beauby commented 7 years ago

Hey @skinnerdev – any news on this front?