Ato Packages: persisting data


#1

I am writing a package which includes options a use time. I am not talking about long term settings, which you might set up in package settings, but options which might change every time you use it.

Currently many functions use the Modal Panel to get additional user options. I would like to store these settings so that they become the default for next time.

How can I store values from within a package? I would need to use these values:

  • between successive calls to the package
  • when Atom is restarted

In a web page, these would be sessionStorage and localStorage, but I don’t know about here.


#2

Atom has serialization. Be careful though; values are serialized constantly, so don’t do anything “heavy”.

In your case though, it looks like you just want config options. See the docs for more detail.

(side note – looks like the docs are glitched, as the Config entry is missing from the latest version) will be fixed in next update


#3

localStorage (and IndexedDB) work in Atom just as you‘d expect them to work in a browser. I‘ve been using this for years in my Atom packages to store information that‘s not meant for a user to edit (which, of course, is still possible). For user preferences, I use package settings.


#4

That’s the one. I should have tried before asking.

sessionStorage also works as expected, so I can hold temporary and permanent data.

Thanks


#5

I see that localStorage is shared by the whole of Atom. Do I use some sort of naming convention to avoid competing with other data?


#6

There is no convention. Personally I prefix my keys with the name if my package (e.g. auto-update-plus.lastUpdate)