live_record 0.3.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -3
- data/app/assets/javascripts/live_record/init.coffee +5 -0
- data/app/assets/javascripts/live_record/model/create.coffee +5 -5
- data/lib/assets/compiled/live_record.js +13 -5
- data/lib/live_record/generators/install_generator.rb +7 -1
- data/lib/live_record/version.rb +1 -1
- data/package.json +1 -1
- metadata +2 -2
- data/.npmignore +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d893afc1c4b65f1decccc6176b8f6e9e5818a2b2e7ac21c5f2b903e6672e0f66
|
4
|
+
data.tar.gz: 4d52d78b3675ce187cfce06daff4cf22e0240508f66f84f808c30be0dbd17e8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ced22fae06d98ca59e4912db8b462998a26ac43708c6da7a8ef0c8fdd8efaed31fd0ac3597e39377ced20fda8a2afff7d2825d1849900b340938ed2ad2a1d8bc
|
7
|
+
data.tar.gz: 70f8f687b78ef517e488f7a534caee2a6b83e29fd6e6f3f5d6a35b33d62b1a5f6dd0bce6bb3ab45c22a46bcc19c41354badea4c3506a9b75e0ec43b344ca8912
|
data/README.md
CHANGED
@@ -157,7 +157,7 @@
|
|
157
157
|
1. Add the following to your `Gemfile`:
|
158
158
|
|
159
159
|
```ruby
|
160
|
-
gem 'live_record', '~> 0.
|
160
|
+
gem 'live_record', '~> 1.0.0'
|
161
161
|
```
|
162
162
|
|
163
163
|
2. Run:
|
@@ -491,6 +491,24 @@
|
|
491
491
|
LiveRecord.Model.all.Book.unsubscribe(subscription);
|
492
492
|
```
|
493
493
|
|
494
|
+
## Setup (if as standalone Node JS module)
|
495
|
+
|
496
|
+
```bash
|
497
|
+
# bash
|
498
|
+
npm install @jrpolidario/live_record --save
|
499
|
+
```
|
500
|
+
|
501
|
+
```js
|
502
|
+
// js
|
503
|
+
import { ActionCable } from 'actioncable'
|
504
|
+
import { LiveRecord } from '@jrpolidario/live_record'
|
505
|
+
|
506
|
+
const cable = ActionCable.createConsumer('wss://RAILS-API-PATH.com/cable')
|
507
|
+
LiveRecord.init(cable)
|
508
|
+
// LiveRecord.Model.create(...)
|
509
|
+
// LiveRecord.Model.create(...)
|
510
|
+
```
|
511
|
+
|
494
512
|
### Ransack Search Queries (Optional)
|
495
513
|
|
496
514
|
* If you need more complex queries to pass into the `.subscribe(where: { ... })` or `.autoload({where: {...}})` above, [ransack](https://github.com/activerecord-hackery/ransack) gem is supported.
|
@@ -602,6 +620,9 @@ end
|
|
602
620
|
|
603
621
|
## JS API
|
604
622
|
|
623
|
+
### `LiveRecord.init(CABLE)`
|
624
|
+
* `CABLE` (ActionCable consumer Object, Required)
|
625
|
+
|
605
626
|
### `LiveRecord.Model.all`
|
606
627
|
* Object of which properties are the models
|
607
628
|
|
@@ -783,8 +804,8 @@ end
|
|
783
804
|
* see [developer_guide.md](developer_guide.md)
|
784
805
|
|
785
806
|
## Changelog
|
786
|
-
* 0.
|
787
|
-
*
|
807
|
+
* 1.0.0
|
808
|
+
* extracted as a Node module (JS code is now modularised, and now requires a major version increment; thus 1.0.0)
|
788
809
|
* 0.3.4
|
789
810
|
* now supports Rails `~> 5.2` after being tested to work
|
790
811
|
* update dependency to Rails (and other dev gems) to use semantic versioning: `~> 5.0`, instead of `>= 5.0, < 5.3`
|
@@ -79,7 +79,7 @@ this.LiveRecord.Model.create = (config) ->
|
|
79
79
|
if config.callbacks.afterReload && !config.reload
|
80
80
|
throw new Error('`afterReload` callback only works with `reload: true`')
|
81
81
|
|
82
|
-
subscription =
|
82
|
+
subscription = LiveRecord.cable.subscriptions.create(
|
83
83
|
{
|
84
84
|
channel: 'LiveRecord::AutoloadsChannel'
|
85
85
|
model_name: Model.modelName
|
@@ -162,7 +162,7 @@ this.LiveRecord.Model.create = (config) ->
|
|
162
162
|
if config.callbacks.afterReload && !config.reload
|
163
163
|
throw new Error('`afterReload` callback only works with `reload: true`')
|
164
164
|
|
165
|
-
subscription =
|
165
|
+
subscription = LiveRecord.cable.subscriptions.create(
|
166
166
|
{
|
167
167
|
channel: 'LiveRecord::PublicationsChannel'
|
168
168
|
model_name: Model.modelName
|
@@ -230,7 +230,7 @@ this.LiveRecord.Model.create = (config) ->
|
|
230
230
|
index = @subscriptions.indexOf(subscription)
|
231
231
|
throw new Error('`subscription` argument does not exist in ' + @modelName + ' subscriptions list') if index == -1
|
232
232
|
|
233
|
-
|
233
|
+
LiveRecord.cable.subscriptions.remove(subscription)
|
234
234
|
|
235
235
|
@subscriptions.splice(index, 1)
|
236
236
|
subscription
|
@@ -246,7 +246,7 @@ this.LiveRecord.Model.create = (config) ->
|
|
246
246
|
config.reload ||= false
|
247
247
|
|
248
248
|
# listen for record changes (update / destroy)
|
249
|
-
subscription = App['live_record_' + @modelName() + '_' + @id()] =
|
249
|
+
subscription = App['live_record_' + @modelName() + '_' + @id()] = LiveRecord.cable.subscriptions.create(
|
250
250
|
{
|
251
251
|
channel: 'LiveRecord::ChangesChannel'
|
252
252
|
model_name: @modelName()
|
@@ -323,7 +323,7 @@ this.LiveRecord.Model.create = (config) ->
|
|
323
323
|
|
324
324
|
Model.prototype.unsubscribe = ->
|
325
325
|
return if @subscription == undefined
|
326
|
-
|
326
|
+
LiveRecord.cable.subscriptions.remove(@subscription)
|
327
327
|
delete this['subscription']
|
328
328
|
|
329
329
|
Model.prototype.isSubscribed = ->
|
@@ -79,6 +79,14 @@
|
|
79
79
|
}
|
80
80
|
};
|
81
81
|
|
82
|
+
}).call(this);
|
83
|
+
(function() {
|
84
|
+
var base;
|
85
|
+
|
86
|
+
(base = this.LiveRecord).init || (base.init = function(cable) {
|
87
|
+
return this.cable = cable;
|
88
|
+
});
|
89
|
+
|
82
90
|
}).call(this);
|
83
91
|
(function() {
|
84
92
|
var base;
|
@@ -182,7 +190,7 @@
|
|
182
190
|
if (config.callbacks.afterReload && !config.reload) {
|
183
191
|
throw new Error('`afterReload` callback only works with `reload: true`');
|
184
192
|
}
|
185
|
-
subscription =
|
193
|
+
subscription = LiveRecord.cable.subscriptions.create({
|
186
194
|
channel: 'LiveRecord::AutoloadsChannel',
|
187
195
|
model_name: Model.modelName,
|
188
196
|
where: config.where
|
@@ -279,7 +287,7 @@
|
|
279
287
|
if (config.callbacks.afterReload && !config.reload) {
|
280
288
|
throw new Error('`afterReload` callback only works with `reload: true`');
|
281
289
|
}
|
282
|
-
subscription =
|
290
|
+
subscription = LiveRecord.cable.subscriptions.create({
|
283
291
|
channel: 'LiveRecord::PublicationsChannel',
|
284
292
|
model_name: Model.modelName,
|
285
293
|
where: config.where
|
@@ -362,7 +370,7 @@
|
|
362
370
|
if (index === -1) {
|
363
371
|
throw new Error('`subscription` argument does not exist in ' + this.modelName + ' subscriptions list');
|
364
372
|
}
|
365
|
-
|
373
|
+
LiveRecord.cable.subscriptions.remove(subscription);
|
366
374
|
this.subscriptions.splice(index, 1);
|
367
375
|
return subscription;
|
368
376
|
};
|
@@ -383,7 +391,7 @@
|
|
383
391
|
return this.subscription;
|
384
392
|
}
|
385
393
|
config.reload || (config.reload = false);
|
386
|
-
subscription = App['live_record_' + this.modelName() + '_' + this.id()] =
|
394
|
+
subscription = App['live_record_' + this.modelName() + '_' + this.id()] = LiveRecord.cable.subscriptions.create({
|
387
395
|
channel: 'LiveRecord::ChangesChannel',
|
388
396
|
model_name: this.modelName(),
|
389
397
|
record_id: this.id()
|
@@ -463,7 +471,7 @@
|
|
463
471
|
if (this.subscription === void 0) {
|
464
472
|
return;
|
465
473
|
}
|
466
|
-
|
474
|
+
LiveRecord.cable.subscriptions.remove(this.subscription);
|
467
475
|
return delete this['subscription'];
|
468
476
|
};
|
469
477
|
Model.prototype.isSubscribed = function() {
|
@@ -49,6 +49,12 @@ module LiveRecord
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
def update_cable_javascript
|
53
|
+
in_root do
|
54
|
+
insert_into_file 'app/assets/javascripts/cable.js', "\n LiveRecord.init(App.cable);", after: "App.cable = ActionCable.createConsumer();"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
52
58
|
private
|
53
59
|
|
54
60
|
def self.next_migration_number(dir)
|
@@ -68,4 +74,4 @@ module LiveRecord
|
|
68
74
|
end
|
69
75
|
end
|
70
76
|
end
|
71
|
-
end
|
77
|
+
end
|
data/lib/live_record/version.rb
CHANGED
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jrpolidario/live_record",
|
3
|
-
"version": "0.
|
3
|
+
"version": "1.0.0",
|
4
4
|
"description": "Auto-syncs records in client-side JS (through a Model DSL) from changes (updates/destroy) in the backend Rails server through ActionCable.\\n Also supports streaming newly created records to client-side JS.\\n Supports lost connection restreaming for both new records (create), and record-changes (updates/destroy).\\n Auto-updates DOM elements mapped to a record attribute, from changes (updates/destroy).",
|
5
5
|
"main": "lib/assets/compiled/live_record.js",
|
6
6
|
"repository": {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: live_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jules Roman B. Polidario
|
@@ -302,7 +302,6 @@ extra_rdoc_files: []
|
|
302
302
|
files:
|
303
303
|
- ".blade.yml"
|
304
304
|
- ".gitignore"
|
305
|
-
- ".npmignore"
|
306
305
|
- ".rspec"
|
307
306
|
- ".travis.yml"
|
308
307
|
- Gemfile
|
@@ -313,6 +312,7 @@ files:
|
|
313
312
|
- app/assets/javascripts/live_record/helpers/case_converter.coffee
|
314
313
|
- app/assets/javascripts/live_record/helpers/load_records.coffee
|
315
314
|
- app/assets/javascripts/live_record/helpers/spaceship.coffee
|
315
|
+
- app/assets/javascripts/live_record/init.coffee
|
316
316
|
- app/assets/javascripts/live_record/model.coffee
|
317
317
|
- app/assets/javascripts/live_record/model/all.coffee
|
318
318
|
- app/assets/javascripts/live_record/model/create.coffee
|
data/.npmignore
DELETED
File without changes
|