isomorfeus-redux 4.0.12 → 4.0.13
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/lib/isomorfeus-redux.rb +1 -0
- data/lib/isomorfeus/core_ext/hash/deep_merge.rb +35 -0
- data/lib/redux/store.rb +39 -0
- data/lib/redux/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bde7f84aef08838a72bd645cc7d301e027b7c0655d7a8b15574b702f8887ea16
|
4
|
+
data.tar.gz: c29f82dd8ddad188745ae302b2eeda6120ceec6b304badfacbad887abfb5a83d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7268658a740a8ddf60d72d02b17982a627d7a5106a392239d95fe604a2a0ad5fc4ef4c30c35e2fe3670bb3adc667a670dd302a2ac2a88e691f2c997cdebe1735
|
7
|
+
data.tar.gz: 9975773c09019966c7eea4847145b24b53b60f946c213ee071521c1b83dd74c9fe11a647a33e4bc56dde89465f2e2a566ea11010fd2da539ab11a9a50c025bff
|
data/lib/isomorfeus-redux.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# taken from: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
|
3
|
+
|
4
|
+
class Hash
|
5
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
6
|
+
#
|
7
|
+
# h1 = { a: true, b: { c: [1, 2, 3] } }
|
8
|
+
# h2 = { a: false, b: { x: [3, 4, 5] } }
|
9
|
+
#
|
10
|
+
# h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
11
|
+
#
|
12
|
+
# Like with Hash#merge in the standard library, a block can be provided
|
13
|
+
# to merge values:
|
14
|
+
#
|
15
|
+
# h1 = { a: 100, b: 200, c: { c1: 100 } }
|
16
|
+
# h2 = { b: 250, c: { c1: 200 } }
|
17
|
+
# h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
|
18
|
+
# # => { a: 100, b: 450, c: { c1: 300 } }
|
19
|
+
def deep_merge(other_hash, &block)
|
20
|
+
dup.deep_merge!(other_hash, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Same as +deep_merge+, but modifies +self+.
|
24
|
+
def deep_merge!(other_hash, &block)
|
25
|
+
merge!(other_hash) do |key, this_val, other_val|
|
26
|
+
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
27
|
+
this_val.deep_merge(other_val, &block)
|
28
|
+
elsif block_given?
|
29
|
+
block.call(key, this_val, other_val)
|
30
|
+
else
|
31
|
+
other_val
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/redux/store.rb
CHANGED
@@ -68,6 +68,9 @@ module Redux
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def initialize(reducer, preloaded_state = `null`, enhancer = `null`)
|
71
|
+
@deferred_actions = {}
|
72
|
+
@deferred_dispatcher = nil
|
73
|
+
@last_dispatch_time = Time.now
|
71
74
|
%x{
|
72
75
|
var compose = (typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) || Opal.global.Redux.compose;
|
73
76
|
var devext_enhance;
|
@@ -122,6 +125,14 @@ module Redux
|
|
122
125
|
Hash.new(`this.native.getState()`)
|
123
126
|
end
|
124
127
|
|
128
|
+
def merge_and_defer_dispatch(action)
|
129
|
+
type = action.delete(:type)
|
130
|
+
@deferred_actions[type] = {} unless @deferred_actions.key?(type)
|
131
|
+
@deferred_actions[type].deep_merge!(action)
|
132
|
+
@last_dispatch_time = `new Date()`
|
133
|
+
create_deferred_dispatcher(`new Date()`) unless @deferred_dispatcher
|
134
|
+
end
|
135
|
+
|
125
136
|
def replace_reducer(next_reducer)
|
126
137
|
`this.native.replaceReducer(next_reducer)`
|
127
138
|
end
|
@@ -130,5 +141,33 @@ module Redux
|
|
130
141
|
def subscribe(&listener)
|
131
142
|
`this.native.subscribe(function() { return listener$.call(); })`
|
132
143
|
end
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
def create_deferred_dispatcher(first)
|
148
|
+
@deferred_dispatcher = true
|
149
|
+
%x{
|
150
|
+
setTimeout(function() {
|
151
|
+
if (#{wait_longer?(first)}) { #{create_deferred_dispatcher(first)} }
|
152
|
+
else { #{dispatch_deferred_dispatches} }
|
153
|
+
}, 25)
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
157
|
+
def dispatch_deferred_dispatches
|
158
|
+
@deferred_dispatcher = false
|
159
|
+
actions = @deferred_actions
|
160
|
+
@deferred_actions = {}
|
161
|
+
actions.each do |type, data|
|
162
|
+
dispatch({type: type}.merge(data))
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def wait_longer?(first)
|
167
|
+
t = `new Date()`
|
168
|
+
return false if (`t - first`) > 50 # ms
|
169
|
+
return false if (`t - #@last_dispatch_time`) > 10 # ms
|
170
|
+
return true
|
171
|
+
end
|
133
172
|
end
|
134
173
|
end
|
data/lib/redux/version.rb
CHANGED
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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -33,6 +33,7 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- README.md
|
35
35
|
- lib/isomorfeus-redux.rb
|
36
|
+
- lib/isomorfeus/core_ext/hash/deep_merge.rb
|
36
37
|
- lib/isomorfeus/promise.rb
|
37
38
|
- lib/isomorfeus/redux_config.rb
|
38
39
|
- lib/redux.rb
|