Module: Isomorfeus::BrowserStoreApi

Included in:
LocalStore, SessionStore
Defined in:
lib/isomorfeus/browser_store_api.rb

Instance Method Summary collapse

Instance Method Details

#notify_subscribersObject



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_clearObject



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

#subscribersObject



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