Class: AppStore
- Inherits:
-
Object
- Object
- AppStore
- Defined in:
- lib/app_store.rb
Class Method Summary collapse
- .method_missing(key, *args, &block) ⇒ Object (also: [], []=, get, set)
- .promise_get(key) ⇒ Object
- .promise_set(key, value) ⇒ Object
- .subscribe(&block) ⇒ Object
- .unsubscribe(unsubscriber) ⇒ Object
Class Method Details
.method_missing(key, *args, &block) ⇒ Object Also known as: [], []=, get, set
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/app_store.rb', line 3 def method_missing(key, *args, &block) if `args.length > 0` # set class state, simply a dispatch action = { type: 'APPLICATION_STATE', name: (`key.endsWith('=')` ? key.chop : key), value: args[0] } Isomorfeus.store.collect_and_defer_dispatch(action) else # check store for value a_state = Isomorfeus.store.get_state if a_state.key?(:application_state) && a_state[:application_state].key?(key) return a_state[:application_state][key] end # otherwise return nil return nil end end |
.promise_get(key) ⇒ Object
26 27 28 |
# File 'lib/app_store.rb', line 26 def promise_get(key) Promise.new.resolve(get(key)) end |
.promise_set(key, value) ⇒ Object
30 31 32 |
# File 'lib/app_store.rb', line 30 def promise_set(key, value) Promise.new.resolve(set(key, value)) end |
.subscribe(&block) ⇒ Object
34 35 36 |
# File 'lib/app_store.rb', line 34 def subscribe(&block) Isomorfeus.store.subscribe(&block) end |
.unsubscribe(unsubscriber) ⇒ Object
38 39 40 |
# File 'lib/app_store.rb', line 38 def unsubscribe(unsubscriber) `unsubscriber()` end |