@davidsouther/jiffies 1.0.0 → 1.1.0

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.
Files changed (172) hide show
  1. package/build/assert.d.ts +23 -23
  2. package/build/assert.js +33 -33
  3. package/build/case.d.ts +1 -1
  4. package/build/case.js +5 -5
  5. package/build/components/button_bar.d.ts +8 -8
  6. package/build/components/button_bar.js +27 -27
  7. package/build/components/inline_edit.d.ts +12 -12
  8. package/build/components/inline_edit.js +48 -48
  9. package/build/components/logger.d.ts +6 -7
  10. package/build/components/logger.js +22 -22
  11. package/build/components/select.d.ts +13 -10
  12. package/build/components/select.js +3 -3
  13. package/build/components/test.d.ts +1 -1
  14. package/build/components/test.js +2 -2
  15. package/build/components/virtual_scroll.d.ts +40 -41
  16. package/build/components/virtual_scroll.js +94 -94
  17. package/build/components/virtual_scroll.test.d.ts +1 -1
  18. package/build/components/virtual_scroll.test.js +21 -21
  19. package/build/context.d.ts +15 -15
  20. package/build/context.js +43 -43
  21. package/build/context.test.d.ts +1 -1
  22. package/build/context.test.js +46 -46
  23. package/build/debounce.d.ts +1 -1
  24. package/build/debounce.js +7 -7
  25. package/build/display.d.ts +5 -5
  26. package/build/display.js +11 -11
  27. package/build/dom/css/border.d.ts +11 -11
  28. package/build/dom/css/border.js +27 -27
  29. package/build/dom/css/constants.d.ts +31 -31
  30. package/build/dom/css/constants.js +28 -28
  31. package/build/dom/css/core.d.ts +5 -5
  32. package/build/dom/css/core.js +24 -24
  33. package/build/dom/css/fstyle.d.ts +5 -5
  34. package/build/dom/css/fstyle.js +32 -32
  35. package/build/dom/css/sizing.d.ts +5 -5
  36. package/build/dom/css/sizing.js +10 -10
  37. package/build/dom/dom.d.ts +26 -27
  38. package/build/dom/dom.js +95 -95
  39. package/build/dom/fc.d.ts +14 -14
  40. package/build/dom/fc.js +36 -35
  41. package/build/dom/fc.test.d.ts +1 -1
  42. package/build/dom/fc.test.js +21 -21
  43. package/build/dom/form/form.app.d.ts +1 -1
  44. package/build/dom/form/form.app.js +23 -23
  45. package/build/dom/form/form.d.ts +26 -26
  46. package/build/dom/form/form.js +34 -34
  47. package/build/dom/form/form.test.js +1 -1
  48. package/build/dom/html.d.ts +113 -117
  49. package/build/dom/html.js +114 -114
  50. package/build/dom/html.test.d.ts +1 -1
  51. package/build/dom/html.test.js +58 -58
  52. package/build/dom/provide.d.ts +3 -3
  53. package/build/dom/provide.js +7 -7
  54. package/build/dom/router/link.d.ts +6 -6
  55. package/build/dom/router/link.js +3 -3
  56. package/build/dom/router/router.d.ts +12 -12
  57. package/build/dom/router/router.js +49 -49
  58. package/build/dom/svg.d.ts +64 -64
  59. package/build/dom/svg.js +65 -65
  60. package/build/dom/test.d.ts +1 -1
  61. package/build/dom/test.js +2 -2
  62. package/build/dom/types/css.d.ts +6612 -6612
  63. package/build/dom/types/css.js +23 -23
  64. package/build/dom/types/dom.js +1 -1
  65. package/build/dom/types/html.d.ts +616 -616
  66. package/build/dom/types/html.js +1 -1
  67. package/build/dom/xml.d.ts +1 -1
  68. package/build/dom/xml.js +4 -5
  69. package/build/equal.d.ts +5 -5
  70. package/build/equal.js +37 -37
  71. package/build/equal.test.d.ts +1 -1
  72. package/build/equal.test.js +20 -20
  73. package/build/flags.d.ts +7 -7
  74. package/build/flags.js +48 -48
  75. package/build/flags.test.d.ts +1 -1
  76. package/build/flags.test.js +35 -35
  77. package/build/fs.d.ts +48 -48
  78. package/build/fs.js +144 -144
  79. package/build/fs.test.d.ts +1 -1
  80. package/build/fs.test.js +43 -43
  81. package/build/generator.d.ts +1 -1
  82. package/build/generator.js +10 -10
  83. package/build/generator.test.d.ts +1 -1
  84. package/build/generator.test.js +24 -24
  85. package/build/is_browser.d.ts +1 -1
  86. package/build/is_browser.js +1 -1
  87. package/build/loader.d.mts +22 -22
  88. package/build/loader.mjs +35 -35
  89. package/build/lock.d.ts +1 -1
  90. package/build/lock.js +23 -23
  91. package/build/lock.test.d.ts +1 -1
  92. package/build/lock.test.js +16 -16
  93. package/build/log.d.ts +26 -26
  94. package/build/log.js +46 -46
  95. package/build/observable/observable.d.ts +83 -0
  96. package/build/observable/observable.js +148 -0
  97. package/build/observable/observable.test.d.ts +1 -0
  98. package/build/observable/observable.test.js +21 -0
  99. package/build/range.d.ts +1 -1
  100. package/build/range.js +7 -7
  101. package/build/result.d.ts +31 -31
  102. package/build/result.js +65 -65
  103. package/build/result.test.d.ts +1 -1
  104. package/build/result.test.js +71 -71
  105. package/build/safe.d.ts +1 -1
  106. package/build/safe.js +10 -10
  107. package/build/scope/describe.d.ts +18 -14
  108. package/build/scope/describe.js +61 -52
  109. package/build/scope/display/console.d.ts +2 -2
  110. package/build/scope/display/console.js +21 -21
  111. package/build/scope/display/dom.d.ts +3 -3
  112. package/build/scope/display/dom.js +26 -26
  113. package/build/scope/display/junit.d.ts +2 -2
  114. package/build/scope/display/junit.js +17 -17
  115. package/build/scope/execute.d.ts +12 -12
  116. package/build/scope/execute.js +85 -85
  117. package/build/scope/expect.d.ts +23 -23
  118. package/build/scope/expect.js +108 -108
  119. package/build/scope/fix.d.ts +4 -4
  120. package/build/scope/fix.js +22 -22
  121. package/build/scope/index.d.ts +3 -3
  122. package/build/scope/index.js +3 -3
  123. package/build/scope/scope.d.ts +17 -17
  124. package/build/scope/scope.js +1 -1
  125. package/build/server/http/apps.d.ts +5 -5
  126. package/build/server/http/apps.js +23 -23
  127. package/build/server/http/css.d.ts +5 -5
  128. package/build/server/http/css.js +50 -47
  129. package/build/server/http/index.d.ts +21 -21
  130. package/build/server/http/index.js +73 -73
  131. package/build/server/http/response.d.ts +4 -4
  132. package/build/server/http/response.js +40 -40
  133. package/build/server/http/sitemap.d.ts +2 -2
  134. package/build/server/http/sitemap.js +42 -42
  135. package/build/server/http/static.d.ts +2 -2
  136. package/build/server/http/static.js +21 -21
  137. package/build/server/http/typescript.d.ts +5 -5
  138. package/build/server/http/typescript.js +40 -40
  139. package/build/server/main.d.ts +2 -2
  140. package/build/server/main.js +9 -9
  141. package/build/test.d.mts +2 -2
  142. package/build/test.mjs +23 -23
  143. package/build/test_all.d.ts +7 -7
  144. package/build/test_all.js +18 -18
  145. package/build/transpile.d.mts +3 -3
  146. package/build/transpile.mjs +18 -18
  147. package/package.json +3 -3
  148. package/src/components/logger.ts +2 -3
  149. package/src/components/virtual_scroll.test.ts +4 -4
  150. package/src/components/virtual_scroll.ts +8 -8
  151. package/src/diff.test.ts +48 -0
  152. package/src/diff.ts +84 -0
  153. package/src/dom/dom.ts +73 -61
  154. package/src/dom/fc.ts +10 -9
  155. package/src/dom/html.test.ts +5 -5
  156. package/src/dom/html.ts +7 -10
  157. package/src/dom/observable.test.ts +43 -0
  158. package/src/dom/observable.ts +11 -0
  159. package/src/dom/router/router.ts +4 -4
  160. package/src/dom/test.ts +5 -1
  161. package/src/dom/xml.ts +1 -2
  162. package/src/index.html +6 -3
  163. package/src/observable/_notes +21 -8
  164. package/src/observable/event.ts +93 -0
  165. package/src/observable/observable.test.ts +73 -0
  166. package/src/observable/observable.ts +403 -0
  167. package/src/scope/describe.ts +14 -1
  168. package/src/scope/display/dom.ts +2 -2
  169. package/src/scope/execute.ts +2 -5
  170. package/src/server/http/css.ts +3 -1
  171. package/src/test_all.ts +10 -8
  172. package/src/observable/observable._js +0 -175
@@ -1,16 +1,16 @@
1
- import { describe, it, expect } from "./scope/index.js";
2
- import { lock } from "./lock.js";
3
- describe("Lock", () => {
4
- it("prevents reentry", function () {
5
- let count = 0;
6
- const inc = lock(function () {
7
- if (count > 4) {
8
- return;
9
- }
10
- inc();
11
- count++;
12
- });
13
- inc();
14
- expect(count).toBe(1);
15
- });
16
- });
1
+ import { describe, it, expect } from "./scope/index.js";
2
+ import { lock } from "./lock.js";
3
+ describe("Lock", () => {
4
+ it("prevents reentry", function () {
5
+ let count = 0;
6
+ const inc = lock(function () {
7
+ if (count > 4) {
8
+ return;
9
+ }
10
+ inc();
11
+ count++;
12
+ });
13
+ inc();
14
+ expect(count).toBe(1);
15
+ });
16
+ });
package/build/log.d.ts CHANGED
@@ -1,26 +1,26 @@
1
- import { Display } from "./display.js";
2
- export interface Log {
3
- (message: Display, data?: {}): void;
4
- }
5
- export interface Logger {
6
- level: Number;
7
- debug: Log;
8
- info: Log;
9
- warn: Log;
10
- error: Log;
11
- }
12
- export declare const LEVEL: {
13
- UNKNOWN: number;
14
- SILENT: number;
15
- DEBUG: number;
16
- VERBOSE: number;
17
- INFO: number;
18
- WARN: number;
19
- ERROR: number;
20
- };
21
- export declare function getLogger(name: string): Logger;
22
- export declare const DEFAULT_LOGGER: Logger;
23
- export declare function debug(message: Display, data?: {}): void;
24
- export declare function info(message: Display, data?: {}): void;
25
- export declare function warn(message: Display, data?: {}): void;
26
- export declare function error(message: Display, data?: {}): void;
1
+ import { Display } from "./display.js";
2
+ export interface Log {
3
+ (message: Display, data?: {}): void;
4
+ }
5
+ export interface Logger {
6
+ level: Number;
7
+ debug: Log;
8
+ info: Log;
9
+ warn: Log;
10
+ error: Log;
11
+ }
12
+ export declare const LEVEL: {
13
+ UNKNOWN: number;
14
+ SILENT: number;
15
+ DEBUG: number;
16
+ VERBOSE: number;
17
+ INFO: number;
18
+ WARN: number;
19
+ ERROR: number;
20
+ };
21
+ export declare function getLogger(name: string): Logger;
22
+ export declare const DEFAULT_LOGGER: Logger;
23
+ export declare function debug(message: Display, data?: {}): void;
24
+ export declare function info(message: Display, data?: {}): void;
25
+ export declare function warn(message: Display, data?: {}): void;
26
+ export declare function error(message: Display, data?: {}): void;
package/build/log.js CHANGED
@@ -1,46 +1,46 @@
1
- import { display } from "./display.js";
2
- export const LEVEL = {
3
- UNKNOWN: 0,
4
- SILENT: 0,
5
- DEBUG: 1,
6
- VERBOSE: 1,
7
- INFO: 2,
8
- WARN: 3,
9
- ERROR: 4,
10
- };
11
- export function getLogger(name) {
12
- const logger = { level: LEVEL.INFO };
13
- const logAt = (level, fn) => (message, data) => level >= (logger.level ?? LEVEL.SILENT)
14
- ? fn(display(message), data)
15
- : undefined;
16
- logger.debug = logAt(LEVEL.VERBOSE, console.debug.bind(console));
17
- logger.info = logAt(LEVEL.INFO, console.info.bind(console));
18
- logger.warn = logAt(LEVEL.WARN, console.warn.bind(console));
19
- logger.error = logAt(LEVEL.ERROR, console.error.bind(console));
20
- return logger;
21
- }
22
- export const DEFAULT_LOGGER = getLogger("default");
23
- export function debug(message, data) {
24
- if (data)
25
- DEFAULT_LOGGER.debug(message, data);
26
- else
27
- DEFAULT_LOGGER.debug(message);
28
- }
29
- export function info(message, data) {
30
- if (data)
31
- DEFAULT_LOGGER.info(message, data);
32
- else
33
- DEFAULT_LOGGER.info(message);
34
- }
35
- export function warn(message, data) {
36
- if (data)
37
- DEFAULT_LOGGER.warn(message, data);
38
- else
39
- DEFAULT_LOGGER.warn(message);
40
- }
41
- export function error(message, data) {
42
- if (data)
43
- DEFAULT_LOGGER.error(message, data);
44
- else
45
- DEFAULT_LOGGER.error(message);
46
- }
1
+ import { display } from "./display.js";
2
+ export const LEVEL = {
3
+ UNKNOWN: 0,
4
+ SILENT: 0,
5
+ DEBUG: 1,
6
+ VERBOSE: 1,
7
+ INFO: 2,
8
+ WARN: 3,
9
+ ERROR: 4,
10
+ };
11
+ export function getLogger(name) {
12
+ const logger = { level: LEVEL.INFO };
13
+ const logAt = (level, fn) => (message, data) => level >= (logger.level ?? LEVEL.SILENT)
14
+ ? fn(display(message), data)
15
+ : undefined;
16
+ logger.debug = logAt(LEVEL.VERBOSE, console.debug.bind(console));
17
+ logger.info = logAt(LEVEL.INFO, console.info.bind(console));
18
+ logger.warn = logAt(LEVEL.WARN, console.warn.bind(console));
19
+ logger.error = logAt(LEVEL.ERROR, console.error.bind(console));
20
+ return logger;
21
+ }
22
+ export const DEFAULT_LOGGER = getLogger("default");
23
+ export function debug(message, data) {
24
+ if (data)
25
+ DEFAULT_LOGGER.debug(message, data);
26
+ else
27
+ DEFAULT_LOGGER.debug(message);
28
+ }
29
+ export function info(message, data) {
30
+ if (data)
31
+ DEFAULT_LOGGER.info(message, data);
32
+ else
33
+ DEFAULT_LOGGER.info(message);
34
+ }
35
+ export function warn(message, data) {
36
+ if (data)
37
+ DEFAULT_LOGGER.warn(message, data);
38
+ else
39
+ DEFAULT_LOGGER.warn(message);
40
+ }
41
+ export function error(message, data) {
42
+ if (data)
43
+ DEFAULT_LOGGER.error(message, data);
44
+ else
45
+ DEFAULT_LOGGER.error(message);
46
+ }
@@ -0,0 +1,83 @@
1
+ import { Logger } from "../log.js";
2
+ export interface Subscriber<T, E> {
3
+ next?: (t: T) => void | Promise<undefined>;
4
+ error?: (e: E) => void | Promise<undefined>;
5
+ complete?: () => void | Promise<undefined>;
6
+ }
7
+ export interface Subscription {
8
+ unsubscribe(): void;
9
+ }
10
+ export interface Observable<T, E = unknown> {
11
+ subscribe(subscriber: Subscriber<T, E>): Subscription;
12
+ pipe<T1>(o1: (t: T) => T1): Observable<T1, E>;
13
+ pipe<T1, T2>(o1: (t: T) => T1, o2: (t: T) => T2): Observable<T2, E>;
14
+ pipe<T1, T2, T3>(o1: (t: T) => T1, o2: (t: T1) => T2, o3: (t: T2) => T3): Observable<T3, E>;
15
+ pipe<T1, T2, T3, T4>(o1: (t: T) => T1, o2: (t: T1) => T2, o3: (t: T2) => T3, o4: (t: T3) => T4): Observable<T4, E>;
16
+ pipe<T1, T2, T3, T4, T5>(o1: (t: T) => T1, o2: (t: T1) => T2, o3: (t: T2) => T3, o4: (t: T3) => T4, o5: (t: T4) => T5): Observable<T5, E>;
17
+ }
18
+ export declare const Observable: {
19
+ of<T, E>(...T: T[]): void;
20
+ combineLatest<T_1, E_1>(...O: Observable<T_1, E_1>[]): void;
21
+ from<T_2, E_2>(f: Promise<T_2> | Iterable<T_2> | Observable<T_2, E_2>): void;
22
+ fromEvent<T_3, E_3>(element: {
23
+ addEventListener<Ev>(fn: (e: Ev) => void): void;
24
+ }, eventName: string): void;
25
+ };
26
+ export declare class Subject<T, E = unknown> implements Subscriber<T, E>, Observable<T, E> {
27
+ #private;
28
+ next(t: T): Promise<undefined>;
29
+ error(e: E): Promise<undefined>;
30
+ complete(): Promise<undefined>;
31
+ subscribe(subscriber: Subscriber<T, E>): Subscription;
32
+ pipe<T1>(o1: (t: T) => T1): Observable<T1, E>;
33
+ pipe<T1, T2>(o1: (t: T) => T1, o2: (t: T1) => T2): Observable<T2, E>;
34
+ pipe<T1, T2, T3>(o1: (t: T) => T1, o2: (t: T1) => T2, o3: (t: T2) => T3): Observable<T3, E>;
35
+ pipe<T1, T2, T3, T4>(o1: (t: T) => T1, o2: (t: T1) => T2, o3: (t: T2) => T3, o4: (t: T3) => T4): Observable<T4, E>;
36
+ pipe<T1, T2, T3, T4, T5>(o1: (t: T) => T1, o2: (t: T1) => T2, o3: (t: T2) => T3, o4: (t: T3) => T4, o5: (t: T4) => T5): Observable<T5, E>;
37
+ }
38
+ export declare class BehaviorSubject<T, E = unknown> extends Subject<T, E> {
39
+ #private;
40
+ constructor(t: T);
41
+ next(t: T): Promise<undefined>;
42
+ subscribe(subscriber: Subscriber<T, E>): Subscription;
43
+ get current(): T;
44
+ }
45
+ export declare class ReplaySubject<T, E = unknown> extends Subject<T, E> {
46
+ #private;
47
+ private readonly n;
48
+ constructor(n: number);
49
+ next(t: T): Promise<undefined>;
50
+ subscribe(subscriber: Subscriber<T, E>): Subscription;
51
+ }
52
+ export interface Next<T> {
53
+ value: T;
54
+ completed: false;
55
+ failed: false;
56
+ }
57
+ export interface Error<E> {
58
+ error: E;
59
+ completed: false;
60
+ failed: true;
61
+ }
62
+ export interface Completed {
63
+ completed: true;
64
+ failed: false;
65
+ }
66
+ export interface Failed {
67
+ completed: true;
68
+ failed: true;
69
+ }
70
+ export declare type Event<T, E> = Next<T> | Error<E> | Completed | Failed;
71
+ export declare const next: <T>(value: T) => Next<T>;
72
+ export declare const error: <E>(e: E) => Error<E>;
73
+ export declare const completed: () => Completed;
74
+ export declare const failed: () => Failed;
75
+ export declare const isNext: <T>(event: Event<T, unknown>) => event is Next<T>;
76
+ export declare const isError: <E>(event: Event<unknown, E>) => event is Error<E>;
77
+ export declare const isCompleted: (event: Event<unknown, unknown>) => event is Completed;
78
+ export declare const isFailed: (event: Event<unknown, unknown>) => event is Failed;
79
+ export declare const isEvent: <T, E>(t: T | Event<T, E>) => t is Event<T, E>;
80
+ export declare const asEvents: <T, E>(a: (T | Event<T, E>)[]) => Event<T, E>[];
81
+ export declare const marbles: <T, E>(events: Event<T, E>[]) => string;
82
+ export declare const collect: <T, E>(input$: Observable<T, E>) => Event<T, E>[];
83
+ export declare const watch: <T, E>(logger?: Logger) => (observable: Observable<T, E>) => void;
@@ -0,0 +1,148 @@
1
+ import { display } from "../display.js";
2
+ import { DEFAULT_LOGGER } from "../log.js";
3
+ export const Observable = {
4
+ of(...T) { },
5
+ combineLatest(...O) { },
6
+ from(f) { },
7
+ fromEvent(element, eventName) { },
8
+ };
9
+ export class Subject {
10
+ #subscribers = new Set();
11
+ #complete = false;
12
+ async next(t) {
13
+ if (this.#complete)
14
+ throw new Error("Cannot call next on a completed subject");
15
+ await Promise.all([...this.#subscribers].map((s) => s.next?.(t)));
16
+ return;
17
+ }
18
+ async error(e) {
19
+ if (this.#complete)
20
+ throw new Error("Cannot call error on a completed subject");
21
+ await Promise.all([...this.#subscribers].map((s) => s.error?.(e)));
22
+ return;
23
+ }
24
+ async complete() {
25
+ if (this.#complete)
26
+ throw new Error("Cannot call complete on a completed subject");
27
+ this.#complete = true;
28
+ const finished = Promise.all([...this.#subscribers].map((s) => s.complete?.()));
29
+ this.#subscribers.clear(); // Free subscribers for garbage collection
30
+ await finished;
31
+ return;
32
+ }
33
+ subscribe(subscriber) {
34
+ if (this.#complete)
35
+ throw new Error("Cannot call subscribe on a completed subject");
36
+ this.#subscribers.add(subscriber);
37
+ return { unsubscribe: () => this.#subscribers.delete(subscriber) };
38
+ }
39
+ pipe(o1, o2, o3, o4, o5) {
40
+ let o = o1.subscribe(this);
41
+ }
42
+ }
43
+ export class BehaviorSubject extends Subject {
44
+ #current;
45
+ constructor(t) {
46
+ super();
47
+ this.#current = t;
48
+ }
49
+ next(t) {
50
+ this.#current = t;
51
+ return super.next(t);
52
+ }
53
+ subscribe(subscriber) {
54
+ subscriber.next?.(this.#current);
55
+ return super.subscribe(subscriber);
56
+ }
57
+ get current() {
58
+ return this.#current;
59
+ }
60
+ }
61
+ export class ReplaySubject extends Subject {
62
+ n;
63
+ #history = [];
64
+ constructor(n) {
65
+ super();
66
+ this.n = n;
67
+ }
68
+ next(t) {
69
+ this.#history.push(t);
70
+ if (this.#history.length > this.n) {
71
+ this.#history.shift();
72
+ }
73
+ return super.next(t);
74
+ }
75
+ subscribe(subscriber) {
76
+ const history = [...this.#history];
77
+ (function send() {
78
+ if (history.length == 0)
79
+ return;
80
+ const t = history.shift();
81
+ subscriber.next?.(t);
82
+ new Promise(send);
83
+ })();
84
+ return super.subscribe(subscriber);
85
+ }
86
+ }
87
+ const operator = {
88
+ filter(fn) { },
89
+ first() { },
90
+ last() { },
91
+ map: (fn) => ({}),
92
+ publishReplay(n) { },
93
+ reduce(fn) { },
94
+ takeUntil(o) { },
95
+ tap(fn) { },
96
+ };
97
+ export const next = (value) => ({
98
+ value,
99
+ completed: false,
100
+ failed: false,
101
+ });
102
+ export const error = (e) => ({
103
+ error: e,
104
+ completed: false,
105
+ failed: true,
106
+ });
107
+ export const completed = () => ({ completed: true, failed: false });
108
+ export const failed = () => ({ completed: true, failed: true });
109
+ export const isNext = (event) => !event.completed && !event.failed && event.value !== undefined;
110
+ export const isError = (event) => event.failed && !event.completed;
111
+ export const isCompleted = (event) => event.completed && !event.failed;
112
+ export const isFailed = (event) => event.completed && event.failed;
113
+ export const isEvent = (t) => {
114
+ const b = t;
115
+ return isNext(b) || isError(b) || isCompleted(b);
116
+ };
117
+ export const asEvents = (a) => a.map((e) => (isEvent(e) ? e : next(e)));
118
+ const marble = (event) => isError(event)
119
+ ? "X"
120
+ : isFailed(event)
121
+ ? "!"
122
+ : isCompleted(event)
123
+ ? "|"
124
+ : `(${display(event.value)})`;
125
+ export const marbles = (events) => `:${events.map(marble).join("-")}`;
126
+ export const collect = (input$) => {
127
+ const collected = [];
128
+ const subscription = input$.subscribe({
129
+ next: (x) => collected.push(next(x)),
130
+ error: (e) => collected.push(error(e)),
131
+ complete: () => collected.push(completed()),
132
+ });
133
+ subscription.unsubscribe();
134
+ return collected;
135
+ };
136
+ export const watch = (logger = DEFAULT_LOGGER) => (observable) => {
137
+ observable.pipe(operator.tap({
138
+ next(t) {
139
+ logger.info(t);
140
+ },
141
+ complete() {
142
+ logger.info("Observable completed");
143
+ },
144
+ error(e) {
145
+ logger.warn(e);
146
+ },
147
+ }));
148
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { describe, expect, it } from "../scope/index.js";
2
+ import { Subject } from "./observable.js";
3
+ describe("Observables", () => {
4
+ describe("basics", () => {
5
+ it("can create and observe a scalar subject", async () => {
6
+ const subject = new Subject();
7
+ let resolved = 42;
8
+ subject.subscribe({
9
+ next: (n) => {
10
+ resolved = n;
11
+ },
12
+ });
13
+ expect(resolved).toBe(42);
14
+ await subject.next(64);
15
+ expect(resolved).toBe(64);
16
+ });
17
+ });
18
+ describe("creation", () => { });
19
+ describe("pipes", () => { });
20
+ describe("subjects", () => { });
21
+ });
package/build/range.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function range(start: number, end: number, stride?: number): number[];
1
+ export declare function range(start: number, end: number, stride?: number): number[];
package/build/range.js CHANGED
@@ -1,7 +1,7 @@
1
- export function range(start, end, stride = 1) {
2
- const range = [];
3
- for (let i = start; i < end; i += stride) {
4
- range.push(i);
5
- }
6
- return range;
7
- }
1
+ export function range(start, end, stride = 1) {
2
+ const range = [];
3
+ for (let i = start; i < end; i += stride) {
4
+ range.push(i);
5
+ }
6
+ return range;
7
+ }
package/build/result.d.ts CHANGED
@@ -1,31 +1,31 @@
1
- export declare type None = null;
2
- export declare type Some<T> = T;
3
- export declare type Option<T> = Some<T> | None;
4
- export declare type Err<E = Error> = {
5
- err: E;
6
- map: <U>(fn: (t: unknown) => Result<U>) => Result<U>;
7
- };
8
- export declare type Ok<T> = {
9
- ok: T;
10
- map: <U>(fn: (t: T) => Result<U>) => Result<U>;
11
- };
12
- export declare type Result<T, E = Error> = Ok<T> | Err<E>;
13
- export declare const isNone: <T>(s: Option<T>) => s is null;
14
- export declare const isSome: <T>(s: Option<T>) => s is T;
15
- export declare function None<T = unknown>(_?: T): Option<T>;
16
- export declare function Some<T>(t: Option<T>): Option<T>;
17
- export declare function Some<T>(t: T): Option<T>;
18
- export declare const isOk: <T, E>(t: Result<T, E>) => t is Ok<T>;
19
- export declare const isErr: <T, E>(e: Result<T, E>) => e is Err<E>;
20
- export declare const isResult: <T, E>(t: Result<T, E>) => t is Result<T, E>;
21
- export declare function Ok<T>(ok: Ok<T>): T;
22
- export declare function Ok<T>(t: T): Ok<T>;
23
- export declare function Err<E>(e: Err<E>): E;
24
- export declare function Err<E>(e: E): Err<E>;
25
- export declare function Err<E>(e: string): Err<E>;
26
- export declare function unwrap<T, E>(result: Result<T, E>): T | never;
27
- export declare function unwrap<O>(some: Option<O>): O | never;
28
- export declare function unwrapOr<T, E>(result: Result<T, E>, def: T): T;
29
- export declare function unwrapOr<T>(some: Some<T>, def: T): T;
30
- export declare function unwrapOrElse<T, E>(result: Result<T, Error>, def: () => T): T;
31
- export declare function unwrapOrElse<T>(some: Some<T>, def: () => T): T;
1
+ export declare type None = null;
2
+ export declare type Some<T> = T;
3
+ export declare type Option<T> = Some<T> | None;
4
+ export declare type Err<E = Error> = {
5
+ err: E;
6
+ map: <U>(fn: (t: unknown) => Result<U>) => Result<U>;
7
+ };
8
+ export declare type Ok<T> = {
9
+ ok: T;
10
+ map: <U>(fn: (t: T) => Result<U>) => Result<U>;
11
+ };
12
+ export declare type Result<T, E = Error> = Ok<T> | Err<E>;
13
+ export declare const isNone: <T>(s: Option<T>) => s is null;
14
+ export declare const isSome: <T>(s: Option<T>) => s is T;
15
+ export declare function None<T = unknown>(_?: T): Option<T>;
16
+ export declare function Some<T>(t: Option<T>): Option<T>;
17
+ export declare function Some<T>(t: T): Option<T>;
18
+ export declare const isOk: <T, E>(t: Result<T, E>) => t is Ok<T>;
19
+ export declare const isErr: <T, E>(e: Result<T, E>) => e is Err<E>;
20
+ export declare const isResult: <T, E>(t: Result<T, E>) => t is Result<T, E>;
21
+ export declare function Ok<T>(ok: Ok<T>): T;
22
+ export declare function Ok<T>(t: T): Ok<T>;
23
+ export declare function Err<E>(e: Err<E>): E;
24
+ export declare function Err<E>(e: E): Err<E>;
25
+ export declare function Err<E>(e: string): Err<E>;
26
+ export declare function unwrap<T, E>(result: Result<T, E>): T | never;
27
+ export declare function unwrap<O>(some: Option<O>): O | never;
28
+ export declare function unwrapOr<T, E>(result: Result<T, E>, def: T): T;
29
+ export declare function unwrapOr<T>(some: Some<T>, def: T): T;
30
+ export declare function unwrapOrElse<T, E>(result: Result<T, Error>, def: () => T): T;
31
+ export declare function unwrapOrElse<T>(some: Some<T>, def: () => T): T;
package/build/result.js CHANGED
@@ -1,65 +1,65 @@
1
- export const isNone = (s) => s == null;
2
- export const isSome = (s) => s != null;
3
- export function None(_) {
4
- return null;
5
- }
6
- export function Some(t) {
7
- return t;
8
- }
9
- export const isOk = (t) => t.ok !== undefined;
10
- export const isErr = (e) => e.err !== undefined;
11
- export const isResult = (t) => isOk(t) || isErr(t);
12
- export function Ok(t) {
13
- return t.ok
14
- ? t.ok
15
- : {
16
- ok: t,
17
- map(fn) {
18
- return fn(Ok(this));
19
- },
20
- };
21
- }
22
- export function Err(e) {
23
- return (e.err ?? {
24
- err: e,
25
- map(_fn) {
26
- return this;
27
- },
28
- });
29
- }
30
- export function unwrap(t) {
31
- if (isNone(t)) {
32
- throw new Error(`Attempted to unwrap None`);
33
- }
34
- if (isErr(t)) {
35
- throw Err(t);
36
- }
37
- if (isOk(t)) {
38
- return Ok(t);
39
- }
40
- return t;
41
- }
42
- export function unwrapOr(t, def) {
43
- if (isNone(t)) {
44
- return def;
45
- }
46
- if (isErr(t)) {
47
- return def;
48
- }
49
- if (isOk(t)) {
50
- return Ok(t);
51
- }
52
- return t;
53
- }
54
- export function unwrapOrElse(t, def) {
55
- if (isNone(t)) {
56
- return def();
57
- }
58
- if (isErr(t)) {
59
- return def();
60
- }
61
- if (isOk(t)) {
62
- return Ok(t);
63
- }
64
- return t;
65
- }
1
+ export const isNone = (s) => s == null;
2
+ export const isSome = (s) => s != null;
3
+ export function None(_) {
4
+ return null;
5
+ }
6
+ export function Some(t) {
7
+ return t;
8
+ }
9
+ export const isOk = (t) => t.ok !== undefined;
10
+ export const isErr = (e) => e.err !== undefined;
11
+ export const isResult = (t) => isOk(t) || isErr(t);
12
+ export function Ok(t) {
13
+ return t.ok
14
+ ? t.ok
15
+ : {
16
+ ok: t,
17
+ map(fn) {
18
+ return fn(Ok(this));
19
+ },
20
+ };
21
+ }
22
+ export function Err(e) {
23
+ return (e.err ?? {
24
+ err: e,
25
+ map(_fn) {
26
+ return this;
27
+ },
28
+ });
29
+ }
30
+ export function unwrap(t) {
31
+ if (isNone(t)) {
32
+ throw new Error(`Attempted to unwrap None`);
33
+ }
34
+ if (isErr(t)) {
35
+ throw Err(t);
36
+ }
37
+ if (isOk(t)) {
38
+ return Ok(t);
39
+ }
40
+ return t;
41
+ }
42
+ export function unwrapOr(t, def) {
43
+ if (isNone(t)) {
44
+ return def;
45
+ }
46
+ if (isErr(t)) {
47
+ return def;
48
+ }
49
+ if (isOk(t)) {
50
+ return Ok(t);
51
+ }
52
+ return t;
53
+ }
54
+ export function unwrapOrElse(t, def) {
55
+ if (isNone(t)) {
56
+ return def();
57
+ }
58
+ if (isErr(t)) {
59
+ return def();
60
+ }
61
+ if (isOk(t)) {
62
+ return Ok(t);
63
+ }
64
+ return t;
65
+ }
@@ -1 +1 @@
1
- export {};
1
+ export {};