isomorfeus-redux 4.0.12 → 4.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6f522bb6c2d8d2b51d82b073e370866e07707b2ddb8687c431fb0c6818225b0
4
- data.tar.gz: 3b90e208b9f3505b71ab85b5711c73304f82743b970329979e6211be654072c3
3
+ metadata.gz: bde7f84aef08838a72bd645cc7d301e027b7c0655d7a8b15574b702f8887ea16
4
+ data.tar.gz: c29f82dd8ddad188745ae302b2eeda6120ceec6b304badfacbad887abfb5a83d
5
5
  SHA512:
6
- metadata.gz: 77a9fbdfcbe6ac471220a6a735f01d5f34fdfb2a4a985bd8bfe835d686954ae9c482fbda0478059a15ba6679014b54633b06fb667739801c68709b1e0b02031d
7
- data.tar.gz: 44a41d2449be7bd81f6fc022c90dfba0b2e39c9c45e42a806e3b36ee85c3b1c4aef2aeb51b444b1d52283d4d2a51654ea8d99109a20153856ee2eaf6cb254f69
6
+ metadata.gz: 7268658a740a8ddf60d72d02b17982a627d7a5106a392239d95fe604a2a0ad5fc4ef4c30c35e2fe3670bb3adc667a670dd302a2ac2a88e691f2c997cdebe1735
7
+ data.tar.gz: 9975773c09019966c7eea4847145b24b53b60f946c213ee071521c1b83dd74c9fe11a647a33e4bc56dde89465f2e2a566ea11010fd2da539ab11a9a50c025bff
@@ -1,6 +1,7 @@
1
1
  if RUBY_ENGINE == 'opal'
2
2
  require 'native'
3
3
  require 'promise'
4
+ require 'isomorfeus/core_ext/hash/deep_merge'
4
5
  require 'redux/version'
5
6
  require 'redux'
6
7
  require 'redux/store'
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Redux
2
- VERSION = '4.0.12'
2
+ VERSION = '4.0.13'
3
3
  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.12
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-28 00:00:00.000000000 Z
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