Closed ricardojmendez closed 8 years ago
Are you saying that passing nil does not work? The keys
parameter must be explicitly undefined?
https://github.com/binaryage/chromex/blob/master/src/lib/chromex/chrome_storage_area.cljs#L13-L14
According to chrome docs, passing null
there should work just fine:
https://developer.chrome.com/extensions/storage#type-StorageArea
Hi Antonin,
I only did a quick read, since the storage functions are not on the demo, and I may have misread it. What's the expected way to get a value out of a specific storage? Say, I want to get keys "timestamp" and "data" out of local
?
please note that [items]
in [items] (<! (get local-storage))
is by design, get
callback is being passed one parameter items
in the future chrome API might decide to pass more parameters into that callback function, so we have to stay flexible (and consistent).
I'm planning on introducing another helper namespace chromex.sugar
which will provide some sugar on top of async calls which receive only one callback parameter. See this file for inspiration:
https://github.com/binaryage/dirac/blob/master/src/shared/dirac/sugar.cljs
I will use it myself for a while on a real project and later will refactor it to have better name conventions.
Perfect, thanks!
Just for record, today I wanted to use the storage api myself and I wrote some incorrect info above.
When you look at default-chrome-storage-area-callback-fn-factory
, it puts on channel a pair [callback-args error]:
https://github.com/binaryage/chromex/blob/master/src/lib/chromex/defaults.cljs#L41
This allows user to test for errors (or skip error checking at all)
I have updated the example code appropriately: https://github.com/binaryage/chromex-sample/commit/150f67e7605cbf59c950a377769e93ed09e6dd81
for inspiration, an implementation of cljs atom synced to one key in local storage: https://github.com/binaryage/dirac/blob/master/src/shared/dirac/options/model.cljs
The get function for the storage areas are missing the optional key or key collections parameters, seems like the only option is to retrieve the entire storage.