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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 509801a74ef9c87f3520ed9312e6cf8cb8c6861f4c250dc2075e7ba8822882c2
4
- data.tar.gz: 220bc5c24e415c54c215b94b983b41bb7ced614090d82d89d347c4544c52ea95
3
+ metadata.gz: d893afc1c4b65f1decccc6176b8f6e9e5818a2b2e7ac21c5f2b903e6672e0f66
4
+ data.tar.gz: 4d52d78b3675ce187cfce06daff4cf22e0240508f66f84f808c30be0dbd17e8d
5
5
  SHA512:
6
- metadata.gz: 949adea6b2fecd574a8fa9c69a4168f87c2231d3e4cf5b3e4920c6d19c155533d320b8bc0393fd93ca4eb2e8354a472c623f948eb199a836cacca041c7cdd4a0
7
- data.tar.gz: 4822d238761d68875d963456ff7c11248368f9a91dfd40ea3f7f98e7d677104a7bc53166af8fcb05b0938bfebdd5f3d152329e44b9252d1e961ba2dc4530a6d4
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.3.6'
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.3.6
787
- * set up as a Node module
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`
@@ -0,0 +1,5 @@
1
+ #= require_self
2
+
3
+ # cable is an ActionCable consumer
4
+ this.LiveRecord.init ||= (cable) ->
5
+ this.cable = cable
@@ -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 = App.cable.subscriptions.create(
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 = App.cable.subscriptions.create(
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
- App.cable.subscriptions.remove(subscription)
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()] = App.cable.subscriptions.create(
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
- App.cable.subscriptions.remove(@subscription)
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 = App.cable.subscriptions.create({
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 = App.cable.subscriptions.create({
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
- App.cable.subscriptions.remove(subscription);
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()] = App.cable.subscriptions.create({
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
- App.cable.subscriptions.remove(this.subscription);
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
@@ -1,3 +1,3 @@
1
1
  module LiveRecord
2
- VERSION = '0.3.6'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jrpolidario/live_record",
3
- "version": "0.3.6",
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.3.6
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