Comments (1)
@ChangePlaces Just to confirm my understanding; you are trying to save the pocket to a JSON file by using JSON.stringify(...)
and then at a later time, restore the data in the JSON file to the pocket? Please correct me if I did not understand your objective correctly.
Currently, there is no functionality to achieve this by default but it can easily be done. You can iterate through the JSON from the file and override whatever is in the localStorage and then call pocket.restore()
which will load the data from the localStorage into the pocket. Alternatively, you can create a pocket, load the JSON from the file, iterate through the JSON keys and add the documents to the pocket e.g.
var jsonFileContent = '{"test": {"name":"test","documents":[{"forename":"Foo","surname":"Bar","_id":"914b2c31-4385-4089-8871-45a779d1202e"}],"options":{"autoCommit":true,"dbname":"pocket"},"length":1}, "user": {"name":"session","documents":[],"options":{"autoCommit":true,"dbname":"pocket"},"length":0}}';
var collections = JSON.parse(jsonFileContent);
var pocket = new Pocket(); // Or an existing pocket
Object.keys(collections).forEach(function(collection){
pocket.collection(collection).remove().insert(collections[collection].documents)
});
To save the data from a pocket to a JSON file I would do the following:
var dataToSaveToFile = JSON.stringify(pocket.collections);
from pocketjs.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pocketjs.