hotwire-livereload 1.4.0 → 1.4.1

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: 76c9e1c7f17f98e067a076d8dfc624d03aa1a7a64784da9fdde0b59f211bebe5
4
- data.tar.gz: 3fa02e7e5a7592c61be7db173ff945f9d2f6da2e29ba4a777072702619b54473
3
+ metadata.gz: 04b3a325fa089d62215f26cf3fbac951e3ac91d0b03af7aed02fa2a49075969e
4
+ data.tar.gz: 24e7339a71da29f35b1930f95f18f0c035aa0221b411fe4a58f27d10384dbb76
5
5
  SHA512:
6
- metadata.gz: 760b3adbb7ef2bc0231f8e90f7ec3b5bfabbc2c01965518d1c69ab9885b0974cbdf0551d1f44e72a498917c55f790947fbad61ec1267973ac139ff85704c2a2f
7
- data.tar.gz: 449e13ba3578d4fcc8e41e4939abecd29ee1a9673cdeaa7a0da24090c31de249868ae7c6541ed37c181cc4a4a23a40c6ee04f83b6922b65be3d9b0d92131d44c
6
+ metadata.gz: 01e7cc071040c5fbafa3fac11adcdfff171695a82c6d6d90db06c8d2010032beb4172ae667b029512737c0afb79c005bcd2e54084661ff662bbae28157087a68
7
+ data.tar.gz: 41e86aa960b2796d65aa26e1d8034a819e5ecdfea578b5995e275f713d666f9b4ffd6a9c6337a6bf17834394ac194382aa2ddf9ff74843fb0f7644ed20bfd2fa
@@ -396,19 +396,19 @@
396
396
  this.subscriptions = subscriptions;
397
397
  this.pendingSubscriptions = [];
398
398
  }
399
- SubscriptionGuarantor2.prototype.guarantee = function guarantee(subscription) {
400
- if (this.pendingSubscriptions.indexOf(subscription) == -1) {
401
- logger.log("SubscriptionGuarantor guaranteeing " + subscription.identifier);
402
- this.pendingSubscriptions.push(subscription);
399
+ SubscriptionGuarantor2.prototype.guarantee = function guarantee(subscription2) {
400
+ if (this.pendingSubscriptions.indexOf(subscription2) == -1) {
401
+ logger.log("SubscriptionGuarantor guaranteeing " + subscription2.identifier);
402
+ this.pendingSubscriptions.push(subscription2);
403
403
  } else {
404
- logger.log("SubscriptionGuarantor already guaranteeing " + subscription.identifier);
404
+ logger.log("SubscriptionGuarantor already guaranteeing " + subscription2.identifier);
405
405
  }
406
406
  this.startGuaranteeing();
407
407
  };
408
- SubscriptionGuarantor2.prototype.forget = function forget(subscription) {
409
- logger.log("SubscriptionGuarantor forgetting " + subscription.identifier);
408
+ SubscriptionGuarantor2.prototype.forget = function forget(subscription2) {
409
+ logger.log("SubscriptionGuarantor forgetting " + subscription2.identifier);
410
410
  this.pendingSubscriptions = this.pendingSubscriptions.filter(function(s) {
411
- return s !== subscription;
411
+ return s !== subscription2;
412
412
  });
413
413
  };
414
414
  SubscriptionGuarantor2.prototype.startGuaranteeing = function startGuaranteeing() {
@@ -422,9 +422,9 @@
422
422
  var _this = this;
423
423
  this.retryTimeout = setTimeout(function() {
424
424
  if (_this.subscriptions && typeof _this.subscriptions.subscribe === "function") {
425
- _this.pendingSubscriptions.map(function(subscription) {
426
- logger.log("SubscriptionGuarantor resubscribing " + subscription.identifier);
427
- _this.subscriptions.subscribe(subscription);
425
+ _this.pendingSubscriptions.map(function(subscription2) {
426
+ logger.log("SubscriptionGuarantor resubscribing " + subscription2.identifier);
427
+ _this.subscriptions.subscribe(subscription2);
428
428
  });
429
429
  }
430
430
  }, 500);
@@ -443,37 +443,37 @@
443
443
  var params = (typeof channel === "undefined" ? "undefined" : _typeof(channel)) === "object" ? channel : {
444
444
  channel
445
445
  };
446
- var subscription = new Subscription(this.consumer, params, mixin);
447
- return this.add(subscription);
446
+ var subscription2 = new Subscription(this.consumer, params, mixin);
447
+ return this.add(subscription2);
448
448
  };
449
- Subscriptions2.prototype.add = function add(subscription) {
450
- this.subscriptions.push(subscription);
449
+ Subscriptions2.prototype.add = function add(subscription2) {
450
+ this.subscriptions.push(subscription2);
451
451
  this.consumer.ensureActiveConnection();
452
- this.notify(subscription, "initialized");
453
- this.subscribe(subscription);
454
- return subscription;
455
- };
456
- Subscriptions2.prototype.remove = function remove2(subscription) {
457
- this.forget(subscription);
458
- if (!this.findAll(subscription.identifier).length) {
459
- this.sendCommand(subscription, "unsubscribe");
452
+ this.notify(subscription2, "initialized");
453
+ this.subscribe(subscription2);
454
+ return subscription2;
455
+ };
456
+ Subscriptions2.prototype.remove = function remove2(subscription2) {
457
+ this.forget(subscription2);
458
+ if (!this.findAll(subscription2.identifier).length) {
459
+ this.sendCommand(subscription2, "unsubscribe");
460
460
  }
461
- return subscription;
461
+ return subscription2;
462
462
  };
463
463
  Subscriptions2.prototype.reject = function reject(identifier) {
464
464
  var _this = this;
465
- return this.findAll(identifier).map(function(subscription) {
466
- _this.forget(subscription);
467
- _this.notify(subscription, "rejected");
468
- return subscription;
465
+ return this.findAll(identifier).map(function(subscription2) {
466
+ _this.forget(subscription2);
467
+ _this.notify(subscription2, "rejected");
468
+ return subscription2;
469
469
  });
470
470
  };
471
- Subscriptions2.prototype.forget = function forget(subscription) {
472
- this.guarantor.forget(subscription);
471
+ Subscriptions2.prototype.forget = function forget(subscription2) {
472
+ this.guarantor.forget(subscription2);
473
473
  this.subscriptions = this.subscriptions.filter(function(s) {
474
- return s !== subscription;
474
+ return s !== subscription2;
475
475
  });
476
- return subscription;
476
+ return subscription2;
477
477
  };
478
478
  Subscriptions2.prototype.findAll = function findAll(identifier) {
479
479
  return this.subscriptions.filter(function(s) {
@@ -482,8 +482,8 @@
482
482
  };
483
483
  Subscriptions2.prototype.reload = function reload() {
484
484
  var _this2 = this;
485
- return this.subscriptions.map(function(subscription) {
486
- return _this2.subscribe(subscription);
485
+ return this.subscriptions.map(function(subscription2) {
486
+ return _this2.subscribe(subscription2);
487
487
  });
488
488
  };
489
489
  Subscriptions2.prototype.notifyAll = function notifyAll(callbackName) {
@@ -491,38 +491,38 @@
491
491
  for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
492
492
  args[_key - 1] = arguments[_key];
493
493
  }
494
- return this.subscriptions.map(function(subscription) {
495
- return _this3.notify.apply(_this3, [subscription, callbackName].concat(args));
494
+ return this.subscriptions.map(function(subscription2) {
495
+ return _this3.notify.apply(_this3, [subscription2, callbackName].concat(args));
496
496
  });
497
497
  };
498
- Subscriptions2.prototype.notify = function notify(subscription, callbackName) {
498
+ Subscriptions2.prototype.notify = function notify(subscription2, callbackName) {
499
499
  for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
500
500
  args[_key2 - 2] = arguments[_key2];
501
501
  }
502
502
  var subscriptions = void 0;
503
- if (typeof subscription === "string") {
504
- subscriptions = this.findAll(subscription);
503
+ if (typeof subscription2 === "string") {
504
+ subscriptions = this.findAll(subscription2);
505
505
  } else {
506
- subscriptions = [subscription];
506
+ subscriptions = [subscription2];
507
507
  }
508
- return subscriptions.map(function(subscription2) {
509
- return typeof subscription2[callbackName] === "function" ? subscription2[callbackName].apply(subscription2, args) : void 0;
508
+ return subscriptions.map(function(subscription3) {
509
+ return typeof subscription3[callbackName] === "function" ? subscription3[callbackName].apply(subscription3, args) : void 0;
510
510
  });
511
511
  };
512
- Subscriptions2.prototype.subscribe = function subscribe(subscription) {
513
- if (this.sendCommand(subscription, "subscribe")) {
514
- this.guarantor.guarantee(subscription);
512
+ Subscriptions2.prototype.subscribe = function subscribe(subscription2) {
513
+ if (this.sendCommand(subscription2, "subscribe")) {
514
+ this.guarantor.guarantee(subscription2);
515
515
  }
516
516
  };
517
517
  Subscriptions2.prototype.confirmSubscription = function confirmSubscription(identifier) {
518
518
  var _this4 = this;
519
519
  logger.log("Subscription confirmed " + identifier);
520
- this.findAll(identifier).map(function(subscription) {
521
- return _this4.guarantor.forget(subscription);
520
+ this.findAll(identifier).map(function(subscription2) {
521
+ return _this4.guarantor.forget(subscription2);
522
522
  });
523
523
  };
524
- Subscriptions2.prototype.sendCommand = function sendCommand(subscription, command) {
525
- var identifier = subscription.identifier;
524
+ Subscriptions2.prototype.sendCommand = function sendCommand(subscription2, command) {
525
+ var identifier = subscription2.identifier;
526
526
  return this.consumer.send({
527
527
  command,
528
528
  identifier
@@ -704,7 +704,8 @@
704
704
 
705
705
  // app/javascript/hotwire-livereload.js
706
706
  var consumer = (0, import_actioncable.createConsumer)();
707
- consumer.subscriptions.create("Hotwire::Livereload::ReloadChannel", {
707
+ var subscription = null;
708
+ var createSubscription = () => consumer.subscriptions.create("Hotwire::Livereload::ReloadChannel", {
708
709
  received: hotwire_livereload_received_default,
709
710
  connected() {
710
711
  console.log("[Hotwire::Livereload] Websocket connected");
@@ -713,8 +714,14 @@
713
714
  console.log("[Hotwire::Livereload] Websocket disconnected");
714
715
  }
715
716
  });
717
+ subscription = createSubscription();
716
718
  document.addEventListener("turbo:load", () => {
717
719
  hotwire_livereload_scroll_position_default.restore();
718
720
  hotwire_livereload_scroll_position_default.remove();
721
+ if (subscription) {
722
+ consumer.subscriptions.remove(subscription);
723
+ subscription = null;
724
+ }
725
+ subscription = createSubscription();
719
726
  });
720
727
  })();
@@ -3,7 +3,9 @@ import received from "./lib/hotwire-livereload-received"
3
3
  import scrollPosition from "./lib/hotwire-livereload-scroll-position"
4
4
 
5
5
  const consumer = createConsumer()
6
- consumer.subscriptions.create("Hotwire::Livereload::ReloadChannel", {
6
+ let subscription = null
7
+
8
+ const createSubscription = () => consumer.subscriptions.create("Hotwire::Livereload::ReloadChannel", {
7
9
  received,
8
10
 
9
11
  connected() {
@@ -15,8 +17,16 @@ consumer.subscriptions.create("Hotwire::Livereload::ReloadChannel", {
15
17
  },
16
18
  })
17
19
 
20
+ subscription = createSubscription()
21
+
18
22
  document.addEventListener("turbo:load", () => {
19
23
  scrollPosition.restore()
20
24
  scrollPosition.remove()
25
+
26
+ if (subscription) {
27
+ consumer.subscriptions.remove(subscription)
28
+ subscription = null
29
+ }
30
+ subscription = createSubscription()
21
31
  })
22
32
 
@@ -1,5 +1,5 @@
1
1
  module Hotwire
2
2
  module Livereload
3
- VERSION = "1.4.0"
3
+ VERSION = "1.4.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotwire-livereload
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Platonov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-30 00:00:00.000000000 Z
11
+ date: 2024-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties