Class: LocalStore

Inherits:
Object
  • Object
show all
Extended by:
Isomorfeus::BrowserStoreApi
Defined in:
lib/local_store.rb

Class Method Summary collapse

Methods included from Isomorfeus::BrowserStoreApi

notify_subscribers, promise_clear, promise_delete, promise_get, promise_set, subscribe, subscribers, unsubscribe

Class Method Details

.clearObject



35
36
37
38
39
# File 'lib/local_store.rb', line 35

def clear
  `Opal.global.localStorage.clear()`
  notify_subscribers
  nil
end

.delete(key) ⇒ Object



29
30
31
32
33
# File 'lib/local_store.rb', line 29

def delete(key)
  `Opal.global.localStorage.removeItem(key)`
  notify_subscribers
  nil
end

.method_missing(key, *args, &block) ⇒ Object Also known as: [], []=, get, set



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/local_store.rb', line 5

def method_missing(key, *args, &block)
  if Isomorfeus.on_browser?
    if `args.length > 0`
      key = `key.endsWith('=')` ? key.chop : key
      value = args[0]
      `Opal.global.localStorage.setItem(key, value)`
      notify_subscribers
      value
    else
      # check store for value
      value = `Opal.global.localStorage.getItem(key)`
      return value if value
    end
  end
  # otherwise return nil
  return nil
end