• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bordoley / reactive-js / 13512219774

25 Feb 2025 02:21AM UTC coverage: 98.225% (-0.2%) from 98.431%
13512219774

push

github

bordoley
Add Streamable.spring() and useSpring/useMeasure hook

877 of 929 branches covered (94.4%)

Branch coverage included in aggregate %.

45 of 56 new or added lines in 6 files covered. (80.36%)

5154 of 5211 relevant lines covered (98.91%)

5149.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/src/concurrent/Streamable/__private__/Streamable.spring.ts
1
import {
3✔
2
  include,
3
  init,
4
  mixInstanceFactory,
5
  props,
6
} from "../../../__internal__/mixins.js";
7
import {
3✔
8
  AnimationStreamLike,
9
  AnimationStreamLike_animation,
10
  ObservableLike,
11
  SchedulerLike,
12
  StreamableLike,
13
  StreamableLike_stream,
14
} from "../../../concurrent.js";
15
import * as Publisher from "../../../events/Publisher.js";
3✔
16
import { EventListenerLike_notify, EventSourceLike } from "../../../events.js";
3✔
17
import {
3✔
18
  Tuple2,
19
  Updater,
20
  compose,
21
  none,
22
  pipe,
23
  scale,
24
} from "../../../functions.js";
25
import * as Disposable from "../../../utils/Disposable.js";
3✔
26
import { BackpressureStrategy } from "../../../utils.js";
27
import * as Observable from "../../Observable.js";
3✔
28
import type * as Streamable from "../../Streamable.js";
29
import * as Subject from "../../Subject.js";
3✔
30
import StreamMixin from "../../__mixins__/StreamMixin.js";
3✔
31

32
const SpringStream_create: (
33
  initialValue: number,
34
  scheduler: SchedulerLike,
35
  animationScheduler: SchedulerLike,
36
  springOptions?: {
37
    readonly stiffness?: number;
38
    readonly damping?: number;
39
    readonly precision?: number;
40
  },
41
  options?: {
42
    readonly backpressureStrategy?: BackpressureStrategy;
43
    readonly replay?: number;
44
    readonly capacity?: number;
45
  },
46
) => AnimationStreamLike<Updater<number>, number> = /*@__PURE__*/ (() => {
3✔
47
  type TProperties = {
48
    [AnimationStreamLike_animation]: EventSourceLike<number>;
49
  };
50

51
  return mixInstanceFactory(
3✔
52
    include(StreamMixin()),
53
    function AnimationStream(
54
      instance: TProperties,
55
      initialValue: number,
56
      scheduler: SchedulerLike,
57
      animationScheduler: SchedulerLike,
58
      springOptions?: {
59
        readonly stiffness?: number;
60
        readonly damping?: number;
61
        readonly precision?: number;
62
      },
63
      options?: {
64
        readonly backpressureStrategy?: BackpressureStrategy;
65
        readonly replay?: number;
66
        readonly capacity?: number;
67
      },
68
    ): AnimationStreamLike<Updater<number>, number> {
NEW
69
      const publisher = (instance[AnimationStreamLike_animation] =
×
70
        Publisher.create<number>());
71

NEW
72
      const accFeedbackStream = Subject.create();
×
73

NEW
74
      const operator = compose(
×
75
        (src: ObservableLike<Updater<number>>) =>
NEW
76
          Observable.zipLatest<number, Updater<number>>(accFeedbackStream, src),
×
77
        Observable.switchMap<Tuple2<number, Updater<number>>, boolean>(
78
          ([acc, update]) =>
NEW
79
            pipe(
×
80
              Observable.spring(springOptions),
81
              Observable.map(scale(acc, update(acc))),
82
              Observable.notify(publisher),
83
              Observable.notify(accFeedbackStream),
84
              Observable.ignoreElements(),
85
              Observable.subscribeOn(animationScheduler),
86
              Observable.startWith<boolean>(true),
87
              Observable.endWith<boolean>(false),
88
            ),
89
          {
90
            innerType: Observable.DeferredObservableWithSideEffectsType,
91
          },
92
        ),
93
      );
94

NEW
95
      init(StreamMixin(), instance, operator, scheduler, options);
×
96

NEW
97
      pipe(
×
98
        instance,
99
        Disposable.add(publisher),
100
        Disposable.add(accFeedbackStream),
101
      );
102

NEW
103
      accFeedbackStream[EventListenerLike_notify](initialValue);
×
104

NEW
105
      return instance;
×
106
    },
107
    props<TProperties>({
108
      [AnimationStreamLike_animation]: none,
109
    }),
110
  );
111
})();
112

113
const Streamable_spring: Streamable.Signature["spring"] = (
3✔
114
  initialValue: number,
115
  creationOptions?: {
116
    readonly animationScheduler?: SchedulerLike;
117
    readonly stiffness?: number;
118
    readonly damping?: number;
119
    readonly precision?: number;
120
  },
121
): StreamableLike<
122
  Updater<number>,
123
  boolean,
124
  AnimationStreamLike<Updater<number>, number>
NEW
125
> => ({
×
126
  [StreamableLike_stream]: (scheduler, options) =>
NEW
127
    SpringStream_create(
×
128
      initialValue,
129
      scheduler,
130
      creationOptions?.animationScheduler ?? scheduler,
×
131
      creationOptions,
132
      options,
133
    ),
134
});
135

136
export default Streamable_spring;
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc