Can you serialize data between program sessions?


#1

For the life of me I can’t figure out how to serialize/deserialize between atom.io restarts. Is it possible? Is state only held while atom.io is open? Im currently using LocalStorage as a persistent alternative.


#2

There’s a help document on serialization:

https://atom.io/docs/latest/advanced/serialization


#3

That is actually a pretty good method that I have been considering using myself. Chromium allows LocalStorage to be arbitrarily large compared to the chrome browser which only allows a small amount of storage.

The problem I have with Atom’s serialization is that it is per-project, which the docs don’t mention. Several times I wanted to store stuff that is available no matter what project is opened and I had to save it in the user’s home folder, which is not a good solution. LocalStorage can be based on anything by using the proper keys. Also you get to use key/values which Atom doesn’t offer.


#4

I’ve read and implemented the instructions on that doc page. And I can only ever get the state to be passed into activate when “reloading” atom. If I close the program and reopen. Nothing is passed in. Is this by design?


#5

Can you show your code?


#6

It’s all but hooked up but you’ll get the idea.


#7

Where is the serializer MyPackageView defined?


#8

@mark_hanh: This code prints an empty Object when atom is started, {hellow:"world"} when restarted using CTRL+ALT+R and again empty Object when we restart the editor.

module.exports =
  activate:(state)->
    console.log state
  serialize:->
    {hellow:"World"}

#9

It works fine for me, with out without any activation events. Can you show me your package.json file?

Some questions…

  • Are you running Atom on a project folder or just starting from a desktop icon?
  • Versions?
    • Atom
    • OS
  • How did you install Atom?

Try renaming or moving your ~/.atom folder and restarting Atom. Then create a new test project with package generator, put in your code, and remove activation events from your package.json. Restart atom and check the console again.


#10

@mark_hanh: Everything else works perfectly for me, I am on Ubuntu 14.04 using atom v0.176. I think I am having trouble with it because of the per-project limitation.
@danielmahon: as @mark_hanh states atom’s serialization is per project. and I don’t think it’s gonna work for open-last-project because It is the one who tells atom about the opened project.


#11

@mark_hanh I discovered that Serialization store only works when you Start atom in that folder. It doesn’t work when you modify the atom.project.path programmatically. Any ideas?


#12

I don’t know what this means. Can you please explain?


#13

Oh, I typed gramatically, It was a typo, I meant programatically. Like
atom.project.setPaths([ThePath])


#14

I just posted an issue on setPaths to atom/atom yesterday. https://github.com/atom/atom/issues/5533 But it was a different problem caused by working serialization.

Back to the topic at hand, I don’t have a clue about your problem. I can’t repeat it on my setup. Sorry.

Edit: Ignore that. I didn’t really try to repeat it with your latest description. I’ll try later.