live_record 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/app/assets/javascripts/live_record/model/create.coffee +13 -12
- data/lib/live_record/version.rb +1 -1
- data/spec/features/live_record_syncing_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 941011b728166d7c1dc7853bcf5f1fc0b02d77da
|
4
|
+
data.tar.gz: ae38164516a9cb42fe726350ca1e816d34f727b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65e3f6082c3b48bd2ce8f96d2c05eeefcbba020dba309229baae94926a8c5df916a3d59e9551fb32dc0ce9a557952fa2303f9363bb6c6b058411d5a2130950e5
|
7
|
+
data.tar.gz: 456403469aa4f8b2c53e374e2cd621a13f9b45a20b1f317381e6d98d2e7c83cb1e0b6c9374215500ab7f62a05a80779dcdbafdfb27a75c7837db5f75a8ada012
|
data/README.md
CHANGED
@@ -117,7 +117,7 @@
|
|
117
117
|
1. Add the following to your `Gemfile`:
|
118
118
|
|
119
119
|
```ruby
|
120
|
-
gem 'live_record', '~> 0.2.
|
120
|
+
gem 'live_record', '~> 0.2.5'
|
121
121
|
```
|
122
122
|
|
123
123
|
2. Run:
|
@@ -284,7 +284,7 @@
|
|
284
284
|
* `"forbidden"` - Current User is not authorized to sync record changes. Happens when Model's `live_record_whitelisted_attributes` method returns empty array.
|
285
285
|
* `"bad_request"` - Happens when `LiveRecord.Model.create({modelName: 'INCORRECTMODELNAME'})`
|
286
286
|
|
287
|
-
8. Load the records into the JS Model-store
|
287
|
+
8. Load the records into the JS Model-store:
|
288
288
|
|
289
289
|
* Any record created/loaded in the JS-store is automatically synced whenever it is updated from the backend
|
290
290
|
* When reconnected after losing connection, the records in the store are synced automatically.
|
@@ -610,6 +610,8 @@
|
|
610
610
|
* MIT
|
611
611
|
|
612
612
|
## Changelog
|
613
|
+
* 0.2.5
|
614
|
+
* fixed a major bug where same-model record instances were all sharing the same `@_callbacks` object, which then effectively calling also callbacks not specifically defined just for a specific record instance.
|
613
615
|
* 0.2.4
|
614
616
|
* you can now pass in `{reload: true}` to `subscribe()` like the folowing:
|
615
617
|
* `MODEL.subscribe({reload: true})` to immediately load all records from backend, and not just the new ones
|
@@ -11,6 +11,19 @@ LiveRecord.Model.create = (config) ->
|
|
11
11
|
if Model.prototype[attribute_key] == undefined
|
12
12
|
Model.prototype[attribute_key] = ->
|
13
13
|
@attributes[attribute_key]
|
14
|
+
|
15
|
+
@_callbacks = {
|
16
|
+
'on:connect': [],
|
17
|
+
'on:disconnect': [],
|
18
|
+
'on:responseError': [],
|
19
|
+
'before:create': [],
|
20
|
+
'after:create': [],
|
21
|
+
'before:update': [],
|
22
|
+
'after:update': [],
|
23
|
+
'before:destroy': [],
|
24
|
+
'after:destroy': []
|
25
|
+
}
|
26
|
+
|
14
27
|
this
|
15
28
|
|
16
29
|
Model.modelName = config.modelName
|
@@ -248,18 +261,6 @@ LiveRecord.Model.create = (config) ->
|
|
248
261
|
'after:destroy': []
|
249
262
|
}
|
250
263
|
|
251
|
-
Model.prototype._callbacks = {
|
252
|
-
'on:connect': [],
|
253
|
-
'on:disconnect': [],
|
254
|
-
'on:responseError': [],
|
255
|
-
'before:create': [],
|
256
|
-
'after:create': [],
|
257
|
-
'before:update': [],
|
258
|
-
'after:update': [],
|
259
|
-
'before:destroy': [],
|
260
|
-
'after:destroy': []
|
261
|
-
}
|
262
|
-
|
263
264
|
# adding new callbackd to the list
|
264
265
|
Model.prototype.addCallback = Model.addCallback = (callbackKey, callbackFunction) ->
|
265
266
|
index = @_callbacks[callbackKey].indexOf(callbackFunction)
|
data/lib/live_record/version.rb
CHANGED
@@ -215,5 +215,22 @@ RSpec.feature 'LiveRecord Syncing', type: :feature do
|
|
215
215
|
wait before: -> { evaluate_script("LiveRecord.Model.all.Post.all[#{post_created_before_disconnection.id}] == undefined") }, becomes: -> (value) { value == false }
|
216
216
|
expect(evaluate_script("LiveRecord.Model.all.Post.all[#{post_created_before_disconnection.id}] == undefined")).to be true
|
217
217
|
end
|
218
|
+
|
219
|
+
scenario 'JS-Client should not have shared callbacks for those callbacks defined only for a particular post record', js: true do
|
220
|
+
visit '/posts'
|
221
|
+
|
222
|
+
wait before: -> { evaluate_script("Object.keys( LiveRecord.Model.all.Post.all ).length") }, becomes: -> (value) { value == posts.count }, duration: 10.seconds
|
223
|
+
expect(evaluate_script("Object.keys( LiveRecord.Model.all.Post.all ).length")).to be posts.count
|
224
|
+
|
225
|
+
execute_script(
|
226
|
+
<<-eos
|
227
|
+
var post1 = LiveRecord.Model.all.Post.all[#{post1.id}];
|
228
|
+
var someCallbackFunction = function() {};
|
229
|
+
post1.addCallback('after:create', someCallbackFunction);
|
230
|
+
eos
|
231
|
+
)
|
232
|
+
|
233
|
+
expect(evaluate_script("LiveRecord.Model.all.Post.all[#{post2.id}]._callbacks['after:create'].length")).to eq 0
|
234
|
+
end
|
218
235
|
end
|
219
236
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: live_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jules Roman B. Polidario
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|