binaryage / chromex

Write Chrome Extensions in ClojureScript
Other
411 stars 21 forks source link

Storage get is missing optional key collections #1

Closed ricardojmendez closed 8 years ago

ricardojmendez commented 8 years ago

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.

darwin commented 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

ricardojmendez commented 8 years ago

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?

darwin commented 8 years ago

Calling test-storage! here outputs this on my machine: console

darwin commented 8 years ago

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.

ricardojmendez commented 8 years ago

Perfect, thanks!

darwin commented 8 years ago

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

darwin commented 8 years ago

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