Module: Isomorfeus::BrowserStoreApi
- Included in:
- LocalStore, SessionStore
- Defined in:
- lib/isomorfeus/browser_store_api.rb
Instance Method Summary collapse
- #notify_subscribers ⇒ Object
- #promise_clear ⇒ Object
- #promise_delete(key) ⇒ Object
- #promise_get(key) ⇒ Object
- #promise_set(key, value) ⇒ Object
- #subscribe(&block) ⇒ Object
- #subscribers ⇒ Object
- #unsubscribe(key) ⇒ Object
Instance Method Details
#notify_subscribers ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/isomorfeus/browser_store_api.rb', line 30 def notify_subscribers return if subscribers.empty? after 0 do subscribers.each_value do |block| block.call end end end |
#promise_clear ⇒ Object
15 16 17 |
# File 'lib/isomorfeus/browser_store_api.rb', line 15 def promise_clear Promise.new.resolve(clear) end |
#promise_delete(key) ⇒ Object
11 12 13 |
# File 'lib/isomorfeus/browser_store_api.rb', line 11 def promise_delete(key) Promise.new.resolve(delete(key)) end |
#promise_get(key) ⇒ Object
3 4 5 |
# File 'lib/isomorfeus/browser_store_api.rb', line 3 def promise_get(key) Promise.new.resolve(get(key)) end |
#promise_set(key, value) ⇒ Object
7 8 9 |
# File 'lib/isomorfeus/browser_store_api.rb', line 7 def promise_set(key, value) Promise.new.resolve(set(key, value)) end |
#subscribe(&block) ⇒ Object
19 20 21 22 23 |
# File 'lib/isomorfeus/browser_store_api.rb', line 19 def subscribe(&block) key = SecureRandom.uuid subscribers[key] = block key end |
#subscribers ⇒ Object
39 40 41 |
# File 'lib/isomorfeus/browser_store_api.rb', line 39 def subscribers @subscribers ||= {} end |
#unsubscribe(key) ⇒ Object
25 26 27 28 |
# File 'lib/isomorfeus/browser_store_api.rb', line 25 def unsubscribe(key) subscribers.delete(key) nil end |