nicklandgrebe / active-resource.js

ActiveResource.js - API resource relational mapping in JavaScript
https://active-resource.js.org
MIT License
133 stars 20 forks source link

IndexedDB support #36

Open antonkomarev opened 5 years ago

antonkomarev commented 5 years ago

I'm trying to put received resource to IndexedDB:

objectStore.put(project, project.id);

But there is an error:

DataCloneError: The object could not be cloned.

My next try was to represent resource as object valid for cloning, but there is no such method:

project.toObject();

Method toArray applicable only for collections, and not working too:

project.toArray();

So, my questions are:

  1. How to convert resource to valid object to put it to IndexedDB
  2. How to convert it back from stored object after get it from IndexedDB
nicklandgrebe commented 5 years ago

This is going to take a bit of time to implement. The easy part is toObject, but getting it back and turning it into a resource is something I've done before personally, but it is not implemented in the core library yet

antonkomarev commented 5 years ago

@nicklandgrebe maybe we could do this task in 2 steps? It will be much better if there will be toObject converter at least.