isomorfeus-redux 4.0.21 → 4.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +113 -3
- data/lib/app_store.rb +42 -0
- data/lib/isomorfeus/browser_store_api.rb +43 -0
- data/lib/isomorfeus/core_ext/kernel.rb +30 -0
- data/lib/isomorfeus/execution_environment.rb +39 -15
- data/lib/isomorfeus-redux.rb +8 -4
- data/lib/local_store.rb +41 -0
- data/lib/redux/reducers.rb +54 -3
- data/lib/redux/store.rb +21 -15
- data/lib/redux/version.rb +1 -1
- data/lib/session_store.rb +41 -0
- metadata +9 -6
- data/lib/isomorfeus/execution_environment_helpers.rb +0 -12
- data/lib/isomorfeus/promise.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac66bd2fa78a0d3dde62ea27ad5d465d0f6298936ebe4d720288b609db23d2e9
|
4
|
+
data.tar.gz: 2577dcb6a4dec4ec430b4a8efb615edb6aa36db290d1c2219a3e9be37296260f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71ad82d18c7f94dce61887613574403d0bb08499d61b24d4bcce818a335aab72c927d880052d66fda709043f3887cab443bd40a316ebfd9c74f32d3a20a5585c
|
7
|
+
data.tar.gz: c939dd916b7870d091047f4a4b777a9c2eaf9c5986972eccd950344c2adb7fd3914237338144b5115aa3a0bbe91b875f15d4c9f5f285399e3f5bbfe35ce7fdcc
|
data/README.md
CHANGED
@@ -34,11 +34,117 @@ For full functionality the following are required:
|
|
34
34
|
For the Gemfile:
|
35
35
|
```ruby
|
36
36
|
gem 'opal', github: 'janbiedermann/opal', branch: 'es6_modules_1_1'
|
37
|
-
gem 'opal-webpack-loader', '~> 0.9.
|
38
|
-
gem 'opal-autoloader', '~> 0.0.3'
|
37
|
+
gem 'opal-webpack-loader', '~> 0.9.10'
|
39
38
|
```
|
40
39
|
|
41
|
-
## Usage
|
40
|
+
## Usage within Isomorfeus
|
41
|
+
|
42
|
+
Lucid Components have store access integrated, see the isomorfeus-react documentation.
|
43
|
+
|
44
|
+
The following stores are available:
|
45
|
+
- AppStore - reactive store managed by redux
|
46
|
+
- LocalStore - convenient access to the Browsers localStorage, changes from within ruby can be subscribed to
|
47
|
+
- SessionStore - convenient access to the Browsers sessionStorage, changes from within ruby can be subscribed to
|
48
|
+
|
49
|
+
### AppStore
|
50
|
+
All keys must be Strings or Symbols! All values must be serializable, simple types preferred!
|
51
|
+
|
52
|
+
Example Usage:
|
53
|
+
```ruby
|
54
|
+
# setting a value:
|
55
|
+
AppStore.some_key = 10
|
56
|
+
AppStore[:some_key] = 10
|
57
|
+
AppStore.set(:some_key, 10)
|
58
|
+
AppStore.promise_set(:some_key, 10)
|
59
|
+
|
60
|
+
# getting a value:
|
61
|
+
val = AppStore.some_key
|
62
|
+
val = AppStore[:some_key]
|
63
|
+
val = AppStore.get(:some_key)
|
64
|
+
AppStore.promise_get(:some_key).then do |val|
|
65
|
+
# do something
|
66
|
+
end
|
67
|
+
|
68
|
+
# subscribing to changes
|
69
|
+
unsub = AppStore.subscribe do
|
70
|
+
@val = AppStore.some_key
|
71
|
+
end
|
72
|
+
|
73
|
+
# MUST be unsibscribed if changes are no longer wanted
|
74
|
+
AppStore.unsubscribe(unsub)
|
75
|
+
```
|
76
|
+
|
77
|
+
### LocalStore
|
78
|
+
All keys and values must be Strings or Symbols!
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
# setting a value:
|
82
|
+
LocalStore.some_key = 10
|
83
|
+
LocalStore[:some_key] = 10
|
84
|
+
LocalStore.set(:some_key, 10)
|
85
|
+
LocalStore.promise_set(:some_key, 10)
|
86
|
+
|
87
|
+
# getting a value:
|
88
|
+
val = LocalStore.some_key
|
89
|
+
val = LocalStore[:some_key]
|
90
|
+
val = LocalStore.get(:some_key)
|
91
|
+
LocalStore.promise_get(:some_key).then do |val|
|
92
|
+
# do something
|
93
|
+
end
|
94
|
+
|
95
|
+
# deleting a value
|
96
|
+
LocalStore.delete(:some_key)
|
97
|
+
LocalStore.promise_delete(:some_key)
|
98
|
+
|
99
|
+
# clearing the store
|
100
|
+
LocalStore.clear
|
101
|
+
LocalStore.promise_clear
|
102
|
+
|
103
|
+
# subscribing to changes
|
104
|
+
unsub = LocalStore.subscribe do
|
105
|
+
@val = LocalStore.some_key
|
106
|
+
end
|
107
|
+
|
108
|
+
# MUST be unsibscribed if changes are no longer wanted
|
109
|
+
LocalStore.unsubscribe(unsub)
|
110
|
+
```
|
111
|
+
|
112
|
+
### SessionStore
|
113
|
+
All keys and values must be Strings or Symbols!
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
# setting a value:
|
117
|
+
SessionStore.some_key = 10
|
118
|
+
SessionStore[:some_key] = 10
|
119
|
+
SessionStore.set(:some_key, 10)
|
120
|
+
SessionStore.promise_set(:some_key, 10)
|
121
|
+
|
122
|
+
# getting a value:
|
123
|
+
val = SessionStore.some_key
|
124
|
+
val = SessionStore[:some_key]
|
125
|
+
val = SessionStore.get(:some_key)
|
126
|
+
SessionStore.promise_get(:some_key).then do |val|
|
127
|
+
# do something
|
128
|
+
end
|
129
|
+
|
130
|
+
# deleting a value
|
131
|
+
SessionStore.delete(:some_key)
|
132
|
+
SessionStore.promise_delete(:some_key)
|
133
|
+
|
134
|
+
# clearing the store
|
135
|
+
SessionStore.clear
|
136
|
+
SessionStore.promise_clear
|
137
|
+
|
138
|
+
# subscribing to changes
|
139
|
+
unsub = SessionStore.subscribe do
|
140
|
+
@val = SessionStore.some_key
|
141
|
+
end
|
142
|
+
|
143
|
+
# MUST be unsibscribed if changes are no longer wanted
|
144
|
+
LocalStore.unsubscribe(unsub)
|
145
|
+
```
|
146
|
+
|
147
|
+
## Advanced Usage
|
42
148
|
Because isomorfeus-redux follows closely the Redux principles/implementation/API and Documentation, most things of the official Redux documentation
|
43
149
|
apply, but in the Ruby way, see:
|
44
150
|
- https://redux.js.org
|
@@ -102,6 +208,7 @@ Isomorfeus.store.subscribe do
|
|
102
208
|
# something useful here
|
103
209
|
end
|
104
210
|
```
|
211
|
+
|
105
212
|
### Setup
|
106
213
|
If isomorfeus-redux is used in isolation, these methods can be used:
|
107
214
|
```ruby
|
@@ -111,3 +218,6 @@ Redux::Store.init! # initializes the global store
|
|
111
218
|
|
112
219
|
### Development Tools
|
113
220
|
The Redux Development Tools allow for detailed debugging of store/state changes: https://github.com/zalmoxisus/redux-devtools-extension
|
221
|
+
|
222
|
+
### Specs
|
223
|
+
Specs for the stores are in isomorfeus-react.
|
data/lib/app_store.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
class AppStore
|
2
|
+
class << self
|
3
|
+
def method_missing(key, *args, &block)
|
4
|
+
if `args.length > 0`
|
5
|
+
# set class state, simply a dispatch
|
6
|
+
action = { type: 'APPLICATION_STATE', name: (`key.endsWith('=')` ? key.chop : key), value: args[0] }
|
7
|
+
Isomorfeus.store.collect_and_defer_dispatch(action)
|
8
|
+
else
|
9
|
+
# check store for value
|
10
|
+
a_state = Isomorfeus.store.get_state
|
11
|
+
if a_state.key?(:application_state) && a_state[:application_state].key?(key)
|
12
|
+
return a_state[:application_state][key]
|
13
|
+
end
|
14
|
+
|
15
|
+
# otherwise return nil
|
16
|
+
return nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
alias [] method_missing
|
21
|
+
alias []= method_missing
|
22
|
+
|
23
|
+
alias get method_missing
|
24
|
+
alias set method_missing
|
25
|
+
|
26
|
+
def promise_get(key)
|
27
|
+
Promise.new.resolve(get(key))
|
28
|
+
end
|
29
|
+
|
30
|
+
def promise_set(key, value)
|
31
|
+
Promise.new.resolve(set(key, value))
|
32
|
+
end
|
33
|
+
|
34
|
+
def subscribe(&block)
|
35
|
+
Isomorfeus.store.subscribe(&block)
|
36
|
+
end
|
37
|
+
|
38
|
+
def unsubscribe(unsubscriber)
|
39
|
+
`unsubscriber()`
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Isomorfeus
|
2
|
+
module BrowserStoreApi
|
3
|
+
def promise_get(key)
|
4
|
+
Promise.new.resolve(get(key))
|
5
|
+
end
|
6
|
+
|
7
|
+
def promise_set(key, value)
|
8
|
+
Promise.new.resolve(set(key, value))
|
9
|
+
end
|
10
|
+
|
11
|
+
def promise_delete(key)
|
12
|
+
Promise.new.resolve(delete(key))
|
13
|
+
end
|
14
|
+
|
15
|
+
def promise_clear
|
16
|
+
Promise.new.resolve(clear)
|
17
|
+
end
|
18
|
+
|
19
|
+
def subscribe(&block)
|
20
|
+
key = SecureRandom.uuid
|
21
|
+
subscribers[key] = block
|
22
|
+
key
|
23
|
+
end
|
24
|
+
|
25
|
+
def unsubscribe(key)
|
26
|
+
subscribers.delete(key)
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def notify_subscribers
|
31
|
+
return if subscribers.empty?
|
32
|
+
after 0 do
|
33
|
+
subscribers.each_value do |block|
|
34
|
+
block.call
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def subscribers
|
40
|
+
@subscribers ||= {}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Kernel
|
2
|
+
def promise_after(time_ms)
|
3
|
+
p = Promise.new
|
4
|
+
after(time_ms) { p.resolve(true) }
|
5
|
+
p
|
6
|
+
end
|
7
|
+
|
8
|
+
def on_browser?; Isomorfeus.on_browser?; end
|
9
|
+
def on_ssr?; Isomorfeus.on_ssr?; end
|
10
|
+
def on_server?; Isomorfeus.on_server?; end
|
11
|
+
def on_desktop?; Isomorfeus.on_desktop?; end
|
12
|
+
def on_ios?; Isomorfeus.on_ios?; end
|
13
|
+
def on_android?; Isomorfeus.on_android?; end
|
14
|
+
def on_mobile?; Isomorfeus.on_mobile?; end
|
15
|
+
def on_database?; Isomorfeus.on_database?; end
|
16
|
+
def on_tvos?; Isomorfeus.on_tvos?; end
|
17
|
+
def on_androidtv?; Isomorfeus.on_androidtv?; end
|
18
|
+
def on_tv?; Isomorfeus.on_tv?; end
|
19
|
+
|
20
|
+
if RUBY_ENGINE == 'opal'
|
21
|
+
def after(time_ms, &block)
|
22
|
+
`setTimeout(#{block.to_n}, time_ms);`
|
23
|
+
end
|
24
|
+
else
|
25
|
+
def after(time_ms, &block)
|
26
|
+
sleep time_ms/1000
|
27
|
+
block.call
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -9,6 +9,9 @@ module Isomorfeus
|
|
9
9
|
attr_accessor :on_android
|
10
10
|
attr_accessor :on_mobile
|
11
11
|
attr_accessor :on_database
|
12
|
+
attr_accessor :on_tvos
|
13
|
+
attr_accessor :on_androidtv
|
14
|
+
attr_accessor :on_tv
|
12
15
|
|
13
16
|
def on_browser?
|
14
17
|
# true if running on browser
|
@@ -49,25 +52,46 @@ module Isomorfeus
|
|
49
52
|
# true if running in database context
|
50
53
|
@on_database
|
51
54
|
end
|
55
|
+
|
56
|
+
def on_tvos?
|
57
|
+
# true if running in react-native on tvOS
|
58
|
+
@on_tvos
|
59
|
+
end
|
60
|
+
|
61
|
+
def on_androidtv?
|
62
|
+
# true if running in react-native on androidtv
|
63
|
+
@on_androidtv
|
64
|
+
end
|
65
|
+
|
66
|
+
def on_tv?
|
67
|
+
# true if running in react-native on a tv
|
68
|
+
@on_tv
|
69
|
+
end
|
52
70
|
end
|
53
71
|
|
54
|
-
self.on_ssr
|
55
|
-
self.on_desktop
|
56
|
-
self.on_ios
|
57
|
-
self.on_android
|
58
|
-
self.on_mobile
|
59
|
-
self.on_database
|
60
|
-
self.on_browser
|
61
|
-
self.on_server
|
72
|
+
self.on_ssr = `(typeof process === 'object' && typeof process.release === 'object' && typeof process.release.name === 'string' && process.release.name === 'node') ? true : false`
|
73
|
+
self.on_desktop = `(typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent.toLowerCase().indexOf(' electron/') > -1) ? true : false`
|
74
|
+
self.on_ios = `(typeof Platform === 'object' && typeof Platform.OS === 'string' && Platform.OS.toLowerCase().includes('ios')) ? true : false`
|
75
|
+
self.on_android = `(typeof Platform === 'object' && typeof Platform.OS === 'string' && Platform.OS.toLowerCase().includes('android')) ? true : false`
|
76
|
+
self.on_mobile = self.on_ios? || self.on_android?
|
77
|
+
self.on_database = false
|
78
|
+
self.on_browser = !self.on_ssr? && !self.on_desktop? && !self.on_mobile? && !self.on_database?
|
79
|
+
self.on_server = false
|
80
|
+
self.on_tvos = false
|
81
|
+
self.on_androidtv = false
|
82
|
+
self.on_tv = false
|
62
83
|
else
|
63
84
|
class << self
|
64
|
-
def on_ssr?;
|
65
|
-
def on_desktop?;
|
66
|
-
def on_ios?;
|
67
|
-
def on_android?;
|
68
|
-
def on_mobile?;
|
69
|
-
def on_database?;
|
70
|
-
def on_browser?;
|
85
|
+
def on_ssr?; false; end
|
86
|
+
def on_desktop?; false; end
|
87
|
+
def on_ios?; false; end
|
88
|
+
def on_android?; false; end
|
89
|
+
def on_mobile?; false; end
|
90
|
+
def on_database?; false; end
|
91
|
+
def on_browser?; false; end
|
92
|
+
def on_tvos?; false; end
|
93
|
+
def on_androidtv?; false; end
|
94
|
+
def on_tv?; false; end
|
71
95
|
|
72
96
|
def on_server?
|
73
97
|
true # so true ...
|
data/lib/isomorfeus-redux.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
require 'opal'
|
2
|
+
require 'isomorfeus/execution_environment'
|
3
|
+
require 'isomorfeus/core_ext/kernel'
|
4
|
+
|
2
5
|
if RUBY_ENGINE == 'opal'
|
3
6
|
require 'native'
|
4
7
|
require 'promise'
|
8
|
+
require 'securerandom'
|
5
9
|
require 'isomorfeus/core_ext/hash/deep_merge'
|
6
|
-
require 'isomorfeus/execution_environment'
|
7
|
-
require 'isomorfeus/execution_environment_helpers'
|
8
10
|
require 'redux'
|
9
11
|
require 'redux/store'
|
10
12
|
require 'redux/reducers'
|
11
13
|
require 'isomorfeus/redux_config'
|
14
|
+
require 'isomorfeus/browser_store_api'
|
15
|
+
require 'local_store'
|
16
|
+
require 'session_store'
|
17
|
+
require 'app_store'
|
12
18
|
|
13
19
|
Redux::Reducers::add_application_reducers_to_store
|
14
20
|
Isomorfeus.init_store
|
@@ -17,8 +23,6 @@ else
|
|
17
23
|
promise_path = File.join(opal_path, 'stdlib', 'promise.rb')
|
18
24
|
require promise_path
|
19
25
|
require 'redux/version'
|
20
|
-
require 'isomorfeus/execution_environment'
|
21
|
-
require 'isomorfeus/execution_environment_helpers'
|
22
26
|
|
23
27
|
Opal.append_path(__dir__.untaint)
|
24
28
|
|
data/lib/local_store.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
class LocalStore
|
2
|
+
extend Isomorfeus::BrowserStoreApi
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def method_missing(key, *args, &block)
|
6
|
+
if Isomorfeus.on_browser?
|
7
|
+
if `args.length > 0`
|
8
|
+
key = `key.endsWith('=')` ? key.chop : key
|
9
|
+
value = args[0]
|
10
|
+
`Opal.global.localStorage.setItem(key, value)`
|
11
|
+
notify_subscribers
|
12
|
+
value
|
13
|
+
else
|
14
|
+
# check store for value
|
15
|
+
value = `Opal.global.localStorage.getItem(key)`
|
16
|
+
return value if value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
# otherwise return nil
|
20
|
+
return nil
|
21
|
+
end
|
22
|
+
|
23
|
+
alias [] method_missing
|
24
|
+
alias []= method_missing
|
25
|
+
|
26
|
+
alias get method_missing
|
27
|
+
alias set method_missing
|
28
|
+
|
29
|
+
def delete(key)
|
30
|
+
`Opal.global.localStorage.removeItem(key)`
|
31
|
+
notify_subscribers
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def clear
|
36
|
+
`Opal.global.localStorage.clear()`
|
37
|
+
notify_subscribers
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/redux/reducers.rb
CHANGED
@@ -10,7 +10,13 @@ module Redux
|
|
10
10
|
action[:set_state]
|
11
11
|
else
|
12
12
|
new_state = {}.merge!(prev_state) # make a copy of state
|
13
|
-
|
13
|
+
if action.key?(:collected)
|
14
|
+
action[:collected].each do |act|
|
15
|
+
new_state.merge!(act[:name] => act[:value])
|
16
|
+
end
|
17
|
+
else
|
18
|
+
new_state.merge!(action[:name] => action[:value])
|
19
|
+
end
|
14
20
|
new_state
|
15
21
|
end
|
16
22
|
else
|
@@ -18,8 +24,53 @@ module Redux
|
|
18
24
|
end
|
19
25
|
end
|
20
26
|
|
21
|
-
Redux
|
22
|
-
|
27
|
+
instance_reducer = Redux.create_reducer do |prev_state, action|
|
28
|
+
case action[:type]
|
29
|
+
when 'INSTANCE_STATE'
|
30
|
+
if action.key?(:set_state)
|
31
|
+
action[:set_state]
|
32
|
+
else
|
33
|
+
new_state = {}.merge!(prev_state) # make a copy of state
|
34
|
+
if action.key?(:collected)
|
35
|
+
action[:collected].each do |act|
|
36
|
+
new_state[act[:object_id]] = {} unless new_state.key?(act[:object_id])
|
37
|
+
new_state[act[:object_id]].merge!(act[:name] => act[:value])
|
38
|
+
end
|
39
|
+
else
|
40
|
+
new_state[action[:object_id]] = {} unless new_state.key?(action[:object_id])
|
41
|
+
new_state[action[:object_id]].merge!(action[:name] => action[:value])
|
42
|
+
end
|
43
|
+
new_state
|
44
|
+
end
|
45
|
+
else
|
46
|
+
prev_state
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class_reducer = Redux.create_reducer do |prev_state, action|
|
51
|
+
case action[:type]
|
52
|
+
when 'CLASS_STATE'
|
53
|
+
if action.key?(:set_state)
|
54
|
+
action[:set_state]
|
55
|
+
else
|
56
|
+
new_state = {}.merge!(prev_state) # make a copy of state
|
57
|
+
if action.key?(:collected)
|
58
|
+
action[:collected].each do |act|
|
59
|
+
new_state[act[:class]] = {} unless new_state.key?(act[:class])
|
60
|
+
new_state[act[:class]].merge!(act[:name] => act[:value])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
new_state[action[:class]] = {} unless new_state.key?(action[:class])
|
64
|
+
new_state[action[:class]].merge!(action[:name] => action[:value])
|
65
|
+
end
|
66
|
+
new_state
|
67
|
+
end
|
68
|
+
else
|
69
|
+
prev_state
|
70
|
+
end
|
71
|
+
end
|
72
|
+
Redux::Store.preloaded_state_merge!(application_state: {}, instance_state: {}, class_state: {})
|
73
|
+
Redux::Store.add_reducers(application_state: app_reducer, instance_state: instance_reducer, class_state: class_reducer)
|
23
74
|
end
|
24
75
|
end
|
25
76
|
end
|
data/lib/redux/store.rb
CHANGED
@@ -125,16 +125,18 @@ module Redux
|
|
125
125
|
Hash.new(`this.native.getState()`)
|
126
126
|
end
|
127
127
|
|
128
|
-
def
|
129
|
-
if Isomorfeus.
|
128
|
+
def collect_and_defer_dispatch(action)
|
129
|
+
if !Isomorfeus.on_ssr?
|
130
130
|
type = action.delete(:type)
|
131
|
-
@deferred_actions[type] =
|
132
|
-
@deferred_actions[type].
|
133
|
-
@last_dispatch_time = `
|
134
|
-
|
131
|
+
@deferred_actions[type] = [] unless @deferred_actions.key?(type)
|
132
|
+
@deferred_actions[type].push(action)
|
133
|
+
@last_dispatch_time = `Date.now()`
|
134
|
+
`console.log(#@last_dispatch_time)`
|
135
|
+
deferred_dispatcher(`Date.now()`) unless @deferred_dispatcher
|
135
136
|
else
|
136
137
|
dispatch(action)
|
137
138
|
end
|
139
|
+
nil
|
138
140
|
end
|
139
141
|
|
140
142
|
def replace_reducer(next_reducer)
|
@@ -143,35 +145,39 @@ module Redux
|
|
143
145
|
|
144
146
|
# returns function needed to unsubscribe the listener
|
145
147
|
def subscribe(&listener)
|
146
|
-
`this.native.subscribe(function() { return listener
|
148
|
+
`this.native.subscribe(function() { return listener.$call(); })`
|
147
149
|
end
|
148
150
|
|
149
151
|
private
|
150
152
|
|
151
|
-
def
|
153
|
+
def deferred_dispatcher(first)
|
152
154
|
@deferred_dispatcher = true
|
153
155
|
%x{
|
154
156
|
setTimeout(function() {
|
155
|
-
if (#{wait_longer?(first)}) { #{
|
157
|
+
if (#{wait_longer?(first)}) { #{deferred_dispatcher(first)} }
|
156
158
|
else { #{dispatch_deferred_dispatches} }
|
157
|
-
},
|
159
|
+
}, 10)
|
158
160
|
}
|
159
161
|
end
|
160
162
|
|
161
163
|
def dispatch_deferred_dispatches
|
164
|
+
`console.log(Date.now())`
|
162
165
|
@deferred_dispatcher = false
|
163
166
|
actions = @deferred_actions
|
164
167
|
@deferred_actions = {}
|
165
168
|
actions.each do |type, data|
|
166
|
-
dispatch(
|
169
|
+
dispatch(type: type, collected: data)
|
167
170
|
end
|
168
171
|
end
|
169
172
|
|
170
173
|
def wait_longer?(first)
|
171
|
-
t = `
|
172
|
-
|
173
|
-
|
174
|
+
t = `Date.now()`
|
175
|
+
time_since_first = `t - first`
|
176
|
+
`console.log('delta', time_since_first)`
|
177
|
+
return true if `typeof Opal.React !== 'undefined' && typeof Opal.React.render_buffer !== 'undefined' && Opal.React.render_buffer.length > 0 && time_since_first < 1000`
|
178
|
+
return false if time_since_first > 100 # ms
|
179
|
+
return false if (`t - #@last_dispatch_time`) > 9 # ms
|
174
180
|
return true
|
175
181
|
end
|
176
182
|
end
|
177
|
-
end
|
183
|
+
end
|
data/lib/redux/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
class SessionStore
|
2
|
+
extend Isomorfeus::BrowserStoreApi
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def method_missing(key, *args, &block)
|
6
|
+
if Isomorfeus.on_browser?
|
7
|
+
if `args.length > 0`
|
8
|
+
key = `key.endsWith('=')` ? key.chop : key
|
9
|
+
value = args[0]
|
10
|
+
`Opal.global.sessionStorage.setItem(key, value)`
|
11
|
+
notify_subscribers
|
12
|
+
value
|
13
|
+
else
|
14
|
+
# check store for value
|
15
|
+
value = `Opal.global.sessionStorage.getItem(key)`
|
16
|
+
return value if value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
# otherwise return nil
|
20
|
+
return nil
|
21
|
+
end
|
22
|
+
|
23
|
+
alias [] method_missing
|
24
|
+
alias []= method_missing
|
25
|
+
|
26
|
+
alias get method_missing
|
27
|
+
alias set method_missing
|
28
|
+
|
29
|
+
def delete(key)
|
30
|
+
`Opal.global.sessionStorage.removeItem(key)`
|
31
|
+
notify_subscribers
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def clear
|
36
|
+
`Opal.global.sessionStorage.clear()`
|
37
|
+
notify_subscribers
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-redux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description: Use
|
41
|
+
description: Use different stores within Isomorfeus and write reducers for redux.
|
42
42
|
email:
|
43
43
|
- jan@kursator.com
|
44
44
|
executables: []
|
@@ -46,16 +46,19 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- README.md
|
49
|
+
- lib/app_store.rb
|
49
50
|
- lib/isomorfeus-redux.rb
|
51
|
+
- lib/isomorfeus/browser_store_api.rb
|
50
52
|
- lib/isomorfeus/core_ext/hash/deep_merge.rb
|
53
|
+
- lib/isomorfeus/core_ext/kernel.rb
|
51
54
|
- lib/isomorfeus/execution_environment.rb
|
52
|
-
- lib/isomorfeus/execution_environment_helpers.rb
|
53
|
-
- lib/isomorfeus/promise.rb
|
54
55
|
- lib/isomorfeus/redux_config.rb
|
56
|
+
- lib/local_store.rb
|
55
57
|
- lib/redux.rb
|
56
58
|
- lib/redux/reducers.rb
|
57
59
|
- lib/redux/store.rb
|
58
60
|
- lib/redux/version.rb
|
61
|
+
- lib/session_store.rb
|
59
62
|
homepage: http://isomorfeus.com
|
60
63
|
licenses:
|
61
64
|
- MIT
|
@@ -79,5 +82,5 @@ requirements: []
|
|
79
82
|
rubygems_version: 3.0.6
|
80
83
|
signing_key:
|
81
84
|
specification_version: 4
|
82
|
-
summary: Redux for
|
85
|
+
summary: Redux and Stores for Isomorfeus.
|
83
86
|
test_files: []
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module Isomorfeus
|
2
|
-
module ExecutionEnvironmentHelpers
|
3
|
-
def on_browser?; Isomorfeus.on_browser?; end
|
4
|
-
def on_ssr?; Isomorfeus.on_ssr?; end
|
5
|
-
def on_desktop?; Isomorfeus.on_desktop?; end
|
6
|
-
def on_ios?; Isomorfeus.on_ios?; end
|
7
|
-
def on_android?; Isomorfeus.on_android?; end
|
8
|
-
def on_mobile?; Isomorfeus.on_mobile?; end
|
9
|
-
def on_database?; Isomorfeus.on_database?; end
|
10
|
-
def on_server?; Isomorfeus.on_server?; end
|
11
|
-
end
|
12
|
-
end
|
data/lib/isomorfeus/promise.rb
DELETED