stimulus-library 0.9.4 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,10 @@ export class TweenNumberController extends BaseController {
8
8
  duration: Number,
9
9
  easing: String,
10
10
  };
11
+ observer;
12
+ observe;
13
+ unobserve;
14
+ teardownObserver;
11
15
  get start() {
12
16
  if (this.hasStartValue) {
13
17
  return this.startValue;
@@ -42,7 +46,11 @@ export class TweenNumberController extends BaseController {
42
46
  return EasingFunctions[str] || fallback;
43
47
  }
44
48
  connect() {
45
- useIntersection(this, this.el, this.appear);
49
+ let { observer, observe, unobserve, teardown, } = useIntersection(this, this.el, this.appear);
50
+ this.observer = observer;
51
+ this.observe = observe;
52
+ this.unobserve = unobserve;
53
+ this.teardownObserver = teardown;
46
54
  }
47
55
  appear(_entry) {
48
56
  this.tween();
@@ -50,16 +58,22 @@ export class TweenNumberController extends BaseController {
50
58
  ;
51
59
  tween() {
52
60
  let startTimestamp = null;
61
+ let self = this;
53
62
  const step = (timestamp) => {
54
63
  if (!startTimestamp) {
55
64
  startTimestamp = timestamp;
56
65
  }
57
66
  const elapsed = timestamp - startTimestamp;
58
67
  const progress = Math.min(elapsed / this.durationMs, 1);
59
- this.element.innerHTML = Math.floor(this.easingFunction(progress) * (this.end - this.start) + this.start).toString();
68
+ this.element.innerHTML =
69
+ Math.floor(this.easingFunction(progress) * (this.end - this.start) + this.start).toString();
60
70
  if (progress < 1) {
61
71
  requestAnimationFrame(step);
62
72
  }
73
+ else {
74
+ self.unobserve?.();
75
+ self.teardownObserver?.();
76
+ }
63
77
  };
64
78
  requestAnimationFrame(step);
65
79
  }
@@ -2,7 +2,9 @@ export * from './use_event_listener';
2
2
  export * from './use_fullscreen';
3
3
  export * from './use_geolocation';
4
4
  export * from './use_injected_html';
5
+ export * from './use_intersection';
5
6
  export * from './use_interval';
6
7
  export * from './use_localstorage';
8
+ export * from './use_mutation_observer';
7
9
  export * from './use_temporary_content';
8
10
  export * from './use_timeout';
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "ruby on rails",
10
10
  "ruby-on-rails"
11
11
  ],
12
- "version": "0.9.4",
12
+ "version": "0.9.6",
13
13
  "license": "MIT",
14
14
  "author": {
15
15
  "name": "Sub-Xaero",