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

bordoley / reactive-js / 14278092116

05 Apr 2025 03:32AM UTC coverage: 88.48% (-6.7%) from 95.167%
14278092116

push

github

bordoley
tests

929 of 1256 branches covered (73.96%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 2 files covered. (100.0%)

229 existing lines in 27 files now uncovered.

6037 of 6617 relevant lines covered (91.23%)

421.48 hits per line

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

26.32
/src/computations/Streamable/__private__/Streamable.spring.ts
1
import { Array_push } from "../../../__internal__/constants.js";
2✔
2
import {
2✔
3
  include,
4
  init,
5
  mixInstanceFactory,
6
  props,
7
} from "../../../__internal__/mixins.js";
8
import {
2✔
9
  PureSynchronousObservableLike,
10
  StoreLike_value,
11
  StreamableLike,
12
  StreamableLike_stream,
13
} from "../../../computations.js";
14
import {
2✔
15
  Optional,
16
  Tuple2,
17
  isFunction,
18
  isNumber,
19
  isReadonlyArray,
20
  pipe,
21
  returns,
22
  tuple,
23
} from "../../../functions.js";
24
import { scale } from "../../../math.js";
2✔
25
import DelegatingPauseableMixin from "../../../utils/__mixins__/DelegatingPauseableMixin.js";
2✔
26
import { BackpressureStrategy, SchedulerLike } from "../../../utils.js";
27
import * as Broadcaster from "../../Broadcaster.js";
2✔
28
import * as Observable from "../../Observable.js";
2✔
29
import * as Runnable from "../../Runnable.js";
2✔
30
import type * as Streamable from "../../Streamable.js";
31
import * as SynchronousObservable from "../../SynchronousObservable.js";
2✔
32
import AnimationStreamMixin from "../../__mixins__/AnimationStreamMixin.js";
2✔
33

34
const Streamable_spring: Streamable.Signature["spring"] = /*@__PURE__*/ (() => {
2✔
35
  type TProperties = {
36
    [StoreLike_value]: number;
37
  };
38

39
  const createSpringStream = mixInstanceFactory(
2✔
40
    include(AnimationStreamMixin(), DelegatingPauseableMixin),
41
    function SpringStream(
42
      this: TProperties,
43
      scheduler: SchedulerLike,
44
      springOptions: Optional<{
45
        readonly stiffness?: number;
46
        readonly damping?: number;
47
        readonly precision?: number;
48
      }>,
49
      options: Optional<{
50
        readonly autoDispose?: boolean;
51
        readonly backpressureStrategy?: BackpressureStrategy;
52
        readonly capacity?: number;
53
      }>,
54
    ): Streamable.SpringStreamLike {
UNCOV
55
      const f = (updater: Streamable.SpringEvent) => {
×
UNCOV
56
        const acc = this[StoreLike_value];
×
UNCOV
57
        const command = isFunction(updater) ? updater(acc) : updater;
×
58
        const springCommandOptions =
UNCOV
59
          isNumber(command) || isReadonlyArray(command)
×
60
            ? springOptions
61
            : {
62
                stiffness: command.stiffness ?? springOptions?.stiffness,
×
63
                damping: command.damping ?? springOptions?.damping,
×
64
                precision: command.precision ?? springOptions?.precision,
×
65
              };
66

67
        const startValue =
UNCOV
68
          isNumber(command) || isReadonlyArray(command) ? acc : command.from;
×
69

UNCOV
70
        const destinations: readonly number[] = isNumber(command)
×
71
          ? [command]
72
          : isReadonlyArray(command)
×
73
            ? command
74
            : isNumber(command.to)
×
75
              ? [command.to]
76
              : command.to;
77

78
        const sources = pipe(
×
79
          destinations,
80
          Runnable.fromReadonlyArray(),
81
          Runnable.scan<number, Tuple2<number, number>>(
82
            ([, prev], v) => tuple(prev, v),
×
83
            returns(tuple(startValue, startValue)),
84
          ),
85
          Runnable.reduce(
86
            (
87
              animations: Array<PureSynchronousObservableLike<number>>,
88
              [prev, next],
89
            ) => {
90
              if (prev !== next) {
×
UNCOV
91
                animations[Array_push](
×
92
                  pipe(
93
                    SynchronousObservable.spring(springCommandOptions),
94
                    SynchronousObservable.map(scale(prev, next)),
95
                  ),
96
                );
97
              }
UNCOV
98
              return animations;
×
99
            },
UNCOV
100
            () => [],
×
101
          ),
102
        );
103

UNCOV
104
        return Observable.concat(...sources);
×
105
      };
106

UNCOV
107
      init(
×
108
        AnimationStreamMixin<Streamable.SpringEvent, number>(),
109
        this,
110
        f,
111
        scheduler,
112
        options,
113
      );
114

UNCOV
115
      pipe(
×
116
        this,
117
        Broadcaster.addEventHandler(v => {
UNCOV
118
          this[StoreLike_value] = v;
×
119
        }),
120
      );
121

UNCOV
122
      return this;
×
123
    },
124
    props({
125
      [StoreLike_value]: 0,
126
    }),
127
  );
128

129
  return (springOptions?: {
2✔
130
    readonly stiffness?: number;
131
    readonly damping?: number;
132
    readonly precision?: number;
133
  }): StreamableLike<
134
    Streamable.SpringEvent,
135
    number,
136
    Streamable.SpringStreamLike
UNCOV
137
  > => ({
×
138
    [StreamableLike_stream]: (scheduler, options) =>
UNCOV
139
      createSpringStream(scheduler, springOptions, options),
×
140
  });
141
})();
142

143
export default Streamable_spring;
2✔
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