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

Posts on data persistence #38

Closed
reachspirit opened this issue Feb 24, 2016 · 4 comments
Closed

Posts on data persistence #38

reachspirit opened this issue Feb 24, 2016 · 4 comments

Comments

@reachspirit
Copy link
Collaborator

Adding favorite reservations requires persistent data support. There are basically two ways: Using the serialize method provided by atom API or read and write to a file. Post supporting materials here.

@reachspirit
Copy link
Collaborator Author

I've been looking for methods of data persistence. The serialize method provided by atom applies typically to classes, while we need to store a global variable history in our case.

https://www.npmjs.com/package/jsonfile

This package provides a way to read from and write to JSON, but I don't know whether it works with local files, for a browser would forbid cross domain access.

@arjunmadan
Copy link
Collaborator

Definitely possible to use this. You can write to the file when Atom closes, or even when you copy/cut and then read from it when Atom opens again or initializes.

You might want to take a look at https://nodejs.org/api/fs.html as well. It's what I'm using for the telemetry part so if you take a look at the code I've added to the telemetry, you should have an example on how to implement reading/writing to a file.

@arjunmadan
Copy link
Collaborator

How'd you implement it would be:

  1. Add the package to package.json and then run apm install.
  2. Add fs = require 'fs' to the top of the file where you're declaring the external modules/packages being used.
  3. Add the readFile function call to the init method and then populate the clipboard, and call appendFile whenever you copy something so that it's stored in the file. (Alternately there might be a shutdown or close method by Atom, and you could just copy the entire contents of the clipboard when this is called.)

@reachspirit
Copy link
Collaborator Author

Thanks for the suggestion! I have managed to preserve the data with serialize method. Not in a standard way, but it's simple and effective.

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

No branches or pull requests

2 participants