reactive-record 0.7.31 → 0.7.32

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
  SHA1:
3
- metadata.gz: b418800c8ef12fe914f24f8a948bc7a923ff944d
4
- data.tar.gz: 93880104e8ae61b61f98f49d334fb2523f908274
3
+ metadata.gz: 280e751548b64eb27ab554fc761593cf55dbcf66
4
+ data.tar.gz: e066f2f6ccd9170f38b4b7c69d83a178dbf20113
5
5
  SHA512:
6
- metadata.gz: 03c0edb07af6406c102deefbf5671f64be507ad6d92a81971eb0adfa2ce28a8542b48d3e63da6af219338225e961aa22e07b841e9e8412626df16d365552f7ce
7
- data.tar.gz: 2dcefccee1f3b7deb11d4ef26736438dfc8fb30a1f6c28172d9927d1229a5a3834cb648abbc46bd1fc74ff9a3985c8c85a38ded7b07d66199f3257e80d69d765
6
+ metadata.gz: 70e341c82153a5ace4a28ed200d6ab6b1c3cc153c8607de3ec4b2a8c2a718f99ecfeb5e1c1ec1fd2c493f4c4dca9afc699f1950c65c5001a17aea097f2d4bdff
7
+ data.tar.gz: 331576cc4d382ad6cf40ff1fb77705c2548c4af48007cfba2e644d60a4c83b79f997ff0cc44d8bfc5691278f8c6ba03521665125c0ac7391905949218c5eedc8
@@ -187,9 +187,10 @@ module ReactiveRecord
187
187
  end
188
188
 
189
189
  def self.schedule_fetch
190
- @fetch_scheduled ||= after(0.01) do
190
+ @fetch_scheduled ||= after(0) do
191
191
  if @pending_fetches.count > 0 # during testing we might reset the context while there are pending fetches otherwise this would never normally happen
192
192
  last_fetch_at = @last_fetch_at
193
+ @last_fetch_at = Time.now
193
194
  pending_fetches = @pending_fetches.uniq
194
195
  models, associations = gather_records(@pending_records, false, nil)
195
196
  log(["Server Fetching: %o", pending_fetches.to_n])
@@ -205,16 +206,15 @@ module ReactiveRecord
205
206
  end
206
207
  log(" Processed in: #{(Time.now-fetch_time).to_i}s")
207
208
  log([" Returned: %o", response.json.to_n])
208
- ReactiveRecord.run_blocks_to_load
209
+ ReactiveRecord.run_blocks_to_load last_fetch_at
209
210
  ReactiveRecord::WhileLoading.loaded_at last_fetch_at
210
211
  ReactiveRecord::WhileLoading.quiet! if @pending_fetches.empty?
211
212
  end.fail do |response|
212
213
  log("Fetch failed", :error)
213
- ReactiveRecord.run_blocks_to_load(response.body)
214
+ ReactiveRecord.run_blocks_to_load(last_fetch_at, response.body)
214
215
  end
215
216
  @pending_fetches = []
216
217
  @pending_records = []
217
- @last_fetch_at = Time.now
218
218
  @fetch_scheduled = nil
219
219
  end
220
220
  end
@@ -11,7 +11,7 @@ module ReactiveRecord
11
11
  result = block.call
12
12
  if @loads_pending
13
13
  @blocks_to_load ||= []
14
- @blocks_to_load << [promise, block]
14
+ @blocks_to_load << [Base.last_fetch_at, promise, block]
15
15
  else
16
16
  promise.resolve result
17
17
  end
@@ -37,19 +37,20 @@ module ReactiveRecord
37
37
  end
38
38
  end
39
39
 
40
- def self.run_blocks_to_load(failure = nil)
40
+ def self.run_blocks_to_load(fetch_id, failure = nil)
41
41
  if @blocks_to_load
42
- blocks_to_load = @blocks_to_load
43
- @blocks_to_load = []
42
+ blocks_to_load_now = @blocks_to_load.select { |data| data.first == fetch_id }
43
+ @blocks_to_load = @blocks_to_load.reject { |data| data.first == fetch_id }
44
44
  @load_stack ||= []
45
- blocks_to_load.each do |promise_and_block|
45
+ blocks_to_load_now.each do |data|
46
+ id, promise, block = data
46
47
  @load_stack << @loads_pending
47
48
  @loads_pending = nil
48
- result = promise_and_block.last.call(failure)
49
+ result = block.call(failure)
49
50
  if check_loads_pending and !failure
50
- @blocks_to_load << promise_and_block
51
+ @blocks_to_load << [Base.last_fetch_at, promise, block]
51
52
  else
52
- promise_and_block.first.resolve result
53
+ promise.resolve result
53
54
  end
54
55
  @loads_pending = @load_stack.pop
55
56
  end
@@ -1,3 +1,3 @@
1
1
  module ReactiveRecord
2
- VERSION = "0.7.31"
2
+ VERSION = "0.7.32"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive-record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.31
4
+ version: 0.7.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitch VanDuyn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-17 00:00:00.000000000 Z
11
+ date: 2015-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails