@davidsouther/jiffies 1.1.0 → 2.0.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.
- package/{build → lib/cjs}/assert.d.ts +23 -23
- package/lib/cjs/assert.js +40 -0
- package/{build → lib/cjs}/case.d.ts +1 -1
- package/lib/cjs/case.js +9 -0
- package/{build → lib/cjs}/components/button_bar.d.ts +8 -8
- package/lib/cjs/components/button_bar.js +29 -0
- package/{build → lib/cjs}/components/inline_edit.d.ts +12 -12
- package/lib/cjs/components/inline_edit.js +51 -0
- package/{build → lib/cjs}/components/logger.d.ts +6 -6
- package/lib/cjs/components/logger.js +27 -0
- package/lib/cjs/components/select.d.ts +10 -0
- package/lib/cjs/components/select.js +6 -0
- package/lib/cjs/components/test.d.ts +1 -0
- package/lib/cjs/components/test.js +7 -0
- package/{build → lib/cjs}/components/virtual_scroll.d.ts +40 -40
- package/lib/cjs/components/virtual_scroll.js +102 -0
- package/{build → lib/cjs}/components/virtual_scroll.test.d.ts +1 -1
- package/lib/cjs/components/virtual_scroll.test.js +22 -0
- package/{build → lib/cjs}/context.d.ts +15 -15
- package/lib/cjs/context.js +48 -0
- package/{build → lib/cjs}/context.test.d.ts +1 -1
- package/lib/cjs/context.test.js +48 -0
- package/{build → lib/cjs}/debounce.d.ts +1 -1
- package/lib/cjs/debounce.js +11 -0
- package/lib/cjs/diff.d.ts +15 -0
- package/lib/cjs/diff.js +58 -0
- package/{build/components/test.d.ts → lib/cjs/diff.test.d.ts} +1 -1
- package/lib/cjs/diff.test.js +41 -0
- package/{build → lib/cjs}/display.d.ts +5 -5
- package/lib/cjs/display.js +16 -0
- package/{build → lib/cjs}/dom/css/border.d.ts +11 -11
- package/lib/cjs/dom/css/border.js +33 -0
- package/{build → lib/cjs}/dom/css/constants.d.ts +31 -31
- package/lib/cjs/dom/css/constants.js +31 -0
- package/{build → lib/cjs}/dom/css/core.d.ts +5 -5
- package/lib/cjs/dom/css/core.js +31 -0
- package/{build → lib/cjs}/dom/css/fstyle.d.ts +5 -5
- package/lib/cjs/dom/css/fstyle.js +36 -0
- package/{build → lib/cjs}/dom/css/sizing.d.ts +5 -5
- package/lib/cjs/dom/css/sizing.js +14 -0
- package/{build → lib/cjs}/dom/dom.d.ts +27 -26
- package/lib/cjs/dom/dom.js +110 -0
- package/{build → lib/cjs}/dom/fc.d.ts +14 -14
- package/lib/cjs/dom/fc.js +39 -0
- package/{build → lib/cjs}/dom/fc.test.d.ts +1 -1
- package/lib/cjs/dom/fc.test.js +23 -0
- package/{build → lib/cjs}/dom/form/form.app.d.ts +1 -1
- package/lib/cjs/dom/form/form.app.js +27 -0
- package/{build → lib/cjs}/dom/form/form.d.ts +26 -26
- package/lib/cjs/dom/form/form.js +49 -0
- package/{build → lib/cjs}/dom/form/form.test.d.ts +0 -0
- package/{build → lib/cjs}/dom/form/form.test.js +1 -1
- package/{build → lib/cjs}/dom/html.d.ts +113 -113
- package/lib/cjs/dom/html.js +119 -0
- package/{build → lib/cjs}/dom/html.test.d.ts +1 -1
- package/lib/cjs/dom/html.test.js +60 -0
- package/lib/cjs/dom/observable.d.ts +2 -0
- package/lib/cjs/dom/observable.js +10 -0
- package/{build/observable → lib/cjs/dom}/observable.test.d.ts +1 -1
- package/lib/cjs/dom/observable.test.js +35 -0
- package/{build → lib/cjs}/dom/provide.d.ts +3 -3
- package/lib/cjs/dom/provide.js +12 -0
- package/{build → lib/cjs}/dom/router/link.d.ts +6 -6
- package/lib/cjs/dom/router/link.js +7 -0
- package/{build → lib/cjs}/dom/router/router.d.ts +12 -12
- package/lib/cjs/dom/router/router.js +52 -0
- package/{build → lib/cjs}/dom/svg.d.ts +64 -64
- package/lib/cjs/dom/svg.js +69 -0
- package/lib/cjs/dom/test.d.ts +1 -0
- package/lib/cjs/dom/test.js +13 -0
- package/{build → lib/cjs}/dom/types/css.d.ts +6612 -6612
- package/lib/cjs/dom/types/css.js +24 -0
- package/{build → lib/cjs}/dom/types/dom.d.ts +0 -0
- package/{build → lib/cjs}/dom/types/dom.js +1 -1
- package/{build → lib/cjs}/dom/types/html.d.ts +616 -616
- package/lib/cjs/dom/types/html.js +2 -0
- package/{build → lib/cjs}/dom/xml.d.ts +1 -1
- package/lib/cjs/dom/xml.js +8 -0
- package/{build → lib/cjs}/equal.d.ts +5 -5
- package/lib/cjs/equal.js +43 -0
- package/{build → lib/cjs}/equal.test.d.ts +1 -1
- package/lib/cjs/equal.test.js +22 -0
- package/{build → lib/cjs}/flags.d.ts +7 -7
- package/lib/cjs/flags.js +52 -0
- package/{build → lib/cjs}/flags.test.d.ts +1 -1
- package/lib/cjs/flags.test.js +37 -0
- package/{build → lib/cjs}/fs.d.ts +48 -48
- package/lib/cjs/fs.js +151 -0
- package/{build → lib/cjs}/fs.test.d.ts +1 -1
- package/lib/cjs/fs.test.js +45 -0
- package/{build → lib/cjs}/generator.d.ts +1 -1
- package/lib/cjs/generator.js +14 -0
- package/{build → lib/cjs}/generator.test.d.ts +1 -1
- package/lib/cjs/generator.test.js +26 -0
- package/{build → lib/cjs}/is_browser.d.ts +1 -1
- package/lib/cjs/is_browser.js +4 -0
- package/{build → lib/cjs}/loader.d.mts +22 -22
- package/lib/cjs/loader.mjs +40 -0
- package/{build → lib/cjs}/lock.d.ts +1 -1
- package/lib/cjs/lock.js +27 -0
- package/{build → lib/cjs}/lock.test.d.ts +1 -1
- package/lib/cjs/lock.test.js +18 -0
- package/{build → lib/cjs}/log.d.ts +26 -26
- package/lib/cjs/log.js +54 -0
- package/lib/cjs/observable/event.d.ts +35 -0
- package/lib/cjs/observable/event.js +61 -0
- package/lib/cjs/observable/observable.d.ts +132 -0
- package/lib/cjs/observable/observable.js +363 -0
- package/lib/cjs/observable/observable.test.d.ts +1 -0
- package/lib/cjs/observable/observable.test.js +65 -0
- package/{build → lib/cjs}/range.d.ts +1 -1
- package/lib/cjs/range.js +11 -0
- package/{build → lib/cjs}/result.d.ts +31 -31
- package/lib/cjs/result.js +80 -0
- package/{build → lib/cjs}/result.test.d.ts +1 -1
- package/lib/cjs/result.test.js +73 -0
- package/{build → lib/cjs}/safe.d.ts +1 -1
- package/lib/cjs/safe.js +14 -0
- package/{build → lib/cjs}/scope/describe.d.ts +18 -18
- package/lib/cjs/scope/describe.js +73 -0
- package/{build → lib/cjs}/scope/display/console.d.ts +2 -2
- package/lib/cjs/scope/display/console.js +25 -0
- package/{build → lib/cjs}/scope/display/dom.d.ts +3 -3
- package/lib/cjs/scope/display/dom.js +30 -0
- package/{build → lib/cjs}/scope/display/junit.d.ts +2 -2
- package/lib/cjs/scope/display/junit.js +21 -0
- package/{build → lib/cjs}/scope/execute.d.ts +12 -12
- package/lib/cjs/scope/execute.js +91 -0
- package/{build → lib/cjs}/scope/expect.d.ts +23 -23
- package/lib/cjs/scope/expect.js +114 -0
- package/{build → lib/cjs}/scope/fix.d.ts +4 -4
- package/lib/cjs/scope/fix.js +26 -0
- package/{build → lib/cjs}/scope/index.d.ts +3 -3
- package/lib/cjs/scope/index.js +15 -0
- package/{build → lib/cjs}/scope/scope.d.ts +17 -17
- package/lib/cjs/scope/scope.js +2 -0
- package/lib/cjs/scope/state.d.ts +1 -0
- package/lib/cjs/scope/state.js +11 -0
- package/{build → lib/cjs}/server/http/apps.d.ts +5 -5
- package/lib/cjs/server/http/apps.js +27 -0
- package/{build → lib/cjs}/server/http/css.d.ts +5 -5
- package/lib/cjs/server/http/css.js +54 -0
- package/{build → lib/cjs}/server/http/index.d.ts +21 -21
- package/lib/cjs/server/http/index.js +77 -0
- package/{build → lib/cjs}/server/http/response.d.ts +4 -4
- package/lib/cjs/server/http/response.js +45 -0
- package/{build → lib/cjs}/server/http/sitemap.d.ts +2 -2
- package/lib/cjs/server/http/sitemap.js +46 -0
- package/{build → lib/cjs}/server/http/static.d.ts +2 -2
- package/lib/cjs/server/http/static.js +25 -0
- package/{build → lib/cjs}/server/http/typescript.d.ts +5 -5
- package/lib/cjs/server/http/typescript.js +44 -0
- package/{build → lib/cjs}/server/main.d.ts +2 -2
- package/lib/cjs/server/main.js +14 -0
- package/{build → lib/cjs}/test.d.mts +2 -2
- package/lib/cjs/test.mjs +28 -0
- package/{build → lib/cjs}/test_all.d.ts +9 -7
- package/lib/cjs/test_all.js +30 -0
- package/{build → lib/cjs}/transpile.d.mts +3 -3
- package/lib/cjs/transpile.mjs +22 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -0
- package/lib/esm/assert.d.ts +23 -0
- package/{build → lib/esm}/assert.js +33 -33
- package/lib/esm/case.d.ts +1 -0
- package/{build → lib/esm}/case.js +5 -5
- package/lib/esm/components/button_bar.d.ts +8 -0
- package/{build → lib/esm}/components/button_bar.js +27 -27
- package/lib/esm/components/inline_edit.d.ts +12 -0
- package/{build → lib/esm}/components/inline_edit.js +48 -48
- package/lib/esm/components/logger.d.ts +6 -0
- package/{build → lib/esm}/components/logger.js +22 -22
- package/lib/esm/components/select.d.ts +10 -0
- package/{build → lib/esm}/components/select.js +3 -3
- package/lib/esm/components/test.d.ts +1 -0
- package/lib/esm/components/test.js +3 -0
- package/lib/esm/components/virtual_scroll.d.ts +40 -0
- package/{build → lib/esm}/components/virtual_scroll.js +94 -94
- package/lib/esm/components/virtual_scroll.test.d.ts +1 -0
- package/{build → lib/esm}/components/virtual_scroll.test.js +20 -21
- package/lib/esm/context.d.ts +15 -0
- package/{build → lib/esm}/context.js +43 -43
- package/lib/esm/context.test.d.ts +1 -0
- package/{build → lib/esm}/context.test.js +46 -46
- package/lib/esm/debounce.d.ts +1 -0
- package/{build → lib/esm}/debounce.js +7 -7
- package/lib/esm/diff.d.ts +15 -0
- package/lib/esm/diff.js +54 -0
- package/lib/esm/diff.test.d.ts +1 -0
- package/lib/esm/diff.test.js +39 -0
- package/lib/esm/display.d.ts +5 -0
- package/{build → lib/esm}/display.js +11 -11
- package/lib/esm/dom/css/border.d.ts +11 -0
- package/{build → lib/esm}/dom/css/border.js +27 -27
- package/lib/esm/dom/css/constants.d.ts +31 -0
- package/{build → lib/esm}/dom/css/constants.js +28 -28
- package/lib/esm/dom/css/core.d.ts +5 -0
- package/{build → lib/esm}/dom/css/core.js +24 -24
- package/lib/esm/dom/css/fstyle.d.ts +5 -0
- package/{build → lib/esm}/dom/css/fstyle.js +32 -32
- package/lib/esm/dom/css/sizing.d.ts +5 -0
- package/{build → lib/esm}/dom/css/sizing.js +10 -10
- package/lib/esm/dom/dom.d.ts +27 -0
- package/{build → lib/esm}/dom/dom.js +104 -95
- package/lib/esm/dom/fc.d.ts +14 -0
- package/{build → lib/esm}/dom/fc.js +35 -36
- package/lib/esm/dom/fc.test.d.ts +1 -0
- package/{build → lib/esm}/dom/fc.test.js +21 -21
- package/lib/esm/dom/form/form.app.d.ts +1 -0
- package/{build → lib/esm}/dom/form/form.app.js +23 -23
- package/lib/esm/dom/form/form.d.ts +26 -0
- package/{build → lib/esm}/dom/form/form.js +34 -34
- package/lib/esm/dom/form/form.test.d.ts +0 -0
- package/lib/esm/dom/form/form.test.js +1 -0
- package/lib/esm/dom/html.d.ts +113 -0
- package/{build → lib/esm}/dom/html.js +114 -114
- package/lib/esm/dom/html.test.d.ts +1 -0
- package/{build → lib/esm}/dom/html.test.js +58 -58
- package/lib/esm/dom/observable.d.ts +2 -0
- package/lib/esm/dom/observable.js +6 -0
- package/lib/esm/dom/observable.test.d.ts +1 -0
- package/lib/esm/dom/observable.test.js +33 -0
- package/lib/esm/dom/provide.d.ts +3 -0
- package/{build → lib/esm}/dom/provide.js +7 -7
- package/lib/esm/dom/router/link.d.ts +6 -0
- package/{build → lib/esm}/dom/router/link.js +3 -3
- package/lib/esm/dom/router/router.d.ts +12 -0
- package/{build → lib/esm}/dom/router/router.js +49 -49
- package/lib/esm/dom/svg.d.ts +64 -0
- package/{build → lib/esm}/dom/svg.js +65 -65
- package/lib/esm/dom/test.d.ts +1 -0
- package/lib/esm/dom/test.js +9 -0
- package/lib/esm/dom/types/css.d.ts +6612 -0
- package/{build → lib/esm}/dom/types/css.js +23 -23
- package/lib/esm/dom/types/dom.d.ts +0 -0
- package/lib/esm/dom/types/dom.js +1 -0
- package/lib/esm/dom/types/html.d.ts +616 -0
- package/{build → lib/esm}/dom/types/html.js +1 -1
- package/lib/esm/dom/xml.d.ts +1 -0
- package/{build → lib/esm}/dom/xml.js +4 -4
- package/lib/esm/equal.d.ts +5 -0
- package/{build → lib/esm}/equal.js +37 -37
- package/lib/esm/equal.test.d.ts +1 -0
- package/{build → lib/esm}/equal.test.js +20 -20
- package/lib/esm/flags.d.ts +7 -0
- package/{build → lib/esm}/flags.js +48 -48
- package/lib/esm/flags.test.d.ts +1 -0
- package/{build → lib/esm}/flags.test.js +35 -35
- package/lib/esm/fs.d.ts +48 -0
- package/{build → lib/esm}/fs.js +144 -144
- package/lib/esm/fs.test.d.ts +1 -0
- package/{build → lib/esm}/fs.test.js +43 -43
- package/lib/esm/generator.d.ts +1 -0
- package/{build → lib/esm}/generator.js +10 -10
- package/lib/esm/generator.test.d.ts +1 -0
- package/{build → lib/esm}/generator.test.js +24 -24
- package/lib/esm/is_browser.d.ts +1 -0
- package/{build → lib/esm}/is_browser.js +1 -1
- package/lib/esm/loader.d.mts +22 -0
- package/{build → lib/esm}/loader.mjs +35 -35
- package/lib/esm/lock.d.ts +1 -0
- package/{build → lib/esm}/lock.js +23 -23
- package/lib/esm/lock.test.d.ts +1 -0
- package/{build → lib/esm}/lock.test.js +16 -16
- package/lib/esm/log.d.ts +26 -0
- package/{build → lib/esm}/log.js +46 -46
- package/lib/esm/observable/event.d.ts +35 -0
- package/lib/esm/observable/event.js +46 -0
- package/lib/esm/observable/observable.d.ts +132 -0
- package/lib/esm/observable/observable.js +343 -0
- package/lib/esm/observable/observable.test.d.ts +1 -0
- package/lib/esm/observable/observable.test.js +63 -0
- package/lib/esm/range.d.ts +1 -0
- package/{build → lib/esm}/range.js +7 -7
- package/lib/esm/result.d.ts +31 -0
- package/{build → lib/esm}/result.js +65 -65
- package/lib/esm/result.test.d.ts +1 -0
- package/{build → lib/esm}/result.test.js +71 -71
- package/lib/esm/safe.d.ts +1 -0
- package/{build → lib/esm}/safe.js +10 -10
- package/lib/esm/scope/describe.d.ts +18 -0
- package/{build → lib/esm}/scope/describe.js +60 -61
- package/lib/esm/scope/display/console.d.ts +2 -0
- package/{build → lib/esm}/scope/display/console.js +21 -21
- package/lib/esm/scope/display/dom.d.ts +3 -0
- package/{build → lib/esm}/scope/display/dom.js +26 -26
- package/lib/esm/scope/display/junit.d.ts +2 -0
- package/{build → lib/esm}/scope/display/junit.js +17 -17
- package/lib/esm/scope/execute.d.ts +12 -0
- package/{build → lib/esm}/scope/execute.js +85 -85
- package/lib/esm/scope/expect.d.ts +23 -0
- package/{build → lib/esm}/scope/expect.js +108 -108
- package/lib/esm/scope/fix.d.ts +4 -0
- package/{build → lib/esm}/scope/fix.js +22 -22
- package/lib/esm/scope/index.d.ts +3 -0
- package/{build → lib/esm}/scope/index.js +3 -3
- package/lib/esm/scope/scope.d.ts +17 -0
- package/{build → lib/esm}/scope/scope.js +1 -1
- package/lib/esm/scope/state.d.ts +1 -0
- package/lib/esm/scope/state.js +7 -0
- package/lib/esm/server/http/apps.d.ts +5 -0
- package/{build → lib/esm}/server/http/apps.js +23 -23
- package/lib/esm/server/http/css.d.ts +5 -0
- package/{build → lib/esm}/server/http/css.js +50 -50
- package/lib/esm/server/http/index.d.ts +21 -0
- package/{build → lib/esm}/server/http/index.js +73 -73
- package/lib/esm/server/http/response.d.ts +4 -0
- package/{build → lib/esm}/server/http/response.js +40 -40
- package/lib/esm/server/http/sitemap.d.ts +2 -0
- package/{build → lib/esm}/server/http/sitemap.js +42 -42
- package/lib/esm/server/http/static.d.ts +2 -0
- package/{build → lib/esm}/server/http/static.js +21 -21
- package/lib/esm/server/http/typescript.d.ts +5 -0
- package/{build → lib/esm}/server/http/typescript.js +40 -40
- package/lib/esm/server/main.d.ts +2 -0
- package/{build → lib/esm}/server/main.js +12 -9
- package/lib/esm/test.d.mts +2 -0
- package/lib/esm/test.mjs +26 -0
- package/lib/esm/test_all.d.ts +9 -0
- package/{build → lib/esm}/test_all.js +28 -18
- package/lib/esm/transpile.d.mts +3 -0
- package/{build → lib/esm}/transpile.mjs +18 -18
- package/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/package.json +13 -14
- package/src/assert.ts +1 -1
- package/src/components/button_bar.ts +3 -3
- package/src/components/inline_edit.ts +3 -3
- package/src/components/logger.ts +3 -3
- package/src/components/select.ts +3 -3
- package/src/components/test.js +3 -2
- package/src/context.ts +3 -3
- package/src/diff.ts +2 -2
- package/src/dom/css/border.ts +3 -3
- package/src/dom/css/core.ts +1 -1
- package/src/dom/css/fstyle.ts +2 -2
- package/src/dom/css/sizing.ts +1 -1
- package/src/dom/dom.ts +1 -1
- package/src/dom/fc.test.ts +3 -3
- package/src/dom/fc.ts +1 -1
- package/src/dom/form/form.app.ts +2 -2
- package/src/dom/form/form.ts +3 -3
- package/src/dom/html.test.ts +3 -3
- package/src/dom/html.ts +1 -1
- package/src/dom/observable.test.ts +6 -6
- package/src/dom/observable.ts +1 -1
- package/src/dom/provide.ts +1 -1
- package/src/dom/router/link.ts +2 -2
- package/src/dom/router/router.ts +2 -2
- package/src/dom/svg.ts +1 -1
- package/src/dom/test.ts +8 -6
- package/src/dom/types/html.ts +1 -1
- package/src/equal.ts +1 -1
- package/src/flags.ts +1 -1
- package/src/fs.ts +4 -4
- package/src/index.html +6 -6
- package/src/observable/event.ts +2 -2
- package/src/observable/observable.test.ts +2 -2
- package/src/observable/observable.ts +72 -12
- package/src/pico/_variables.scss +1 -1
- package/src/pico/layout/_sectioning.scss +2 -0
- package/src/result.ts +1 -1
- package/src/scope/describe.ts +2 -5
- package/src/scope/display/console.ts +4 -4
- package/src/scope/display/dom.ts +6 -6
- package/src/scope/display/junit.ts +3 -3
- package/src/scope/execute.ts +2 -2
- package/src/scope/expect.ts +3 -3
- package/src/scope/state.ts +10 -0
- package/src/server/http/sitemap.ts +1 -1
- package/src/server/main.ts +9 -2
- package/src/test.mjs +22 -18
- package/src/test_all.ts +10 -0
- package/build/components/select.d.ts +0 -13
- package/build/components/test.js +0 -2
- package/build/dom/test.d.ts +0 -1
- package/build/dom/test.js +0 -2
- package/build/observable/observable.d.ts +0 -83
- package/build/observable/observable.js +0 -148
- package/build/observable/observable.test.js +0 -21
- package/build/test.mjs +0 -23
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Logger } from "../log.js";
|
|
2
|
+
export interface FullSubscriber<T, E> {
|
|
3
|
+
next?: (t: T) => void | Promise<undefined>;
|
|
4
|
+
error?: (e: E) => void | Promise<undefined>;
|
|
5
|
+
complete?: () => void | Promise<undefined>;
|
|
6
|
+
}
|
|
7
|
+
export declare type Subscriber<T, E> = FullSubscriber<T, E> | ((t: T) => void | Promise<undefined>);
|
|
8
|
+
export interface Subscription {
|
|
9
|
+
unsubscribe(): void;
|
|
10
|
+
}
|
|
11
|
+
export interface Observable<T, E = unknown> {
|
|
12
|
+
subscribe(subscriber: Subscriber<T, E>): Subscription;
|
|
13
|
+
pipe<T1>(o1: Subscriber<T, E> & Observable<T1, E>): Observable<T1, E>;
|
|
14
|
+
pipe<T1, T2>(o1: Subscriber<T, E> & Observable<T1, E>, o2: Subscriber<T1, E> & Observable<T2, E>): Observable<T2, E>;
|
|
15
|
+
filter(fn: (t: T) => boolean): Observable<T, E>;
|
|
16
|
+
distinct(fn?: (t1: T, t2: T) => boolean): Observable<T, E>;
|
|
17
|
+
map<U>(fn: (t: T) => U): Observable<U, E>;
|
|
18
|
+
reduce<A>(fn: (acc: A, t: T) => A, init: A): Observable<A, E>;
|
|
19
|
+
replay(n: number): Observable<T, E>;
|
|
20
|
+
tap(s: Subscriber<T, E>): Observable<T, E>;
|
|
21
|
+
}
|
|
22
|
+
export declare const Observable: {
|
|
23
|
+
of<T, E>(...ts: T[]): Observable<T, E>;
|
|
24
|
+
combineLatest<T1, T2, E_1>(o1: Observable<T1, E_1>, o2: Observable<T2, E_1>): Observable<[T1, T2], E_1>;
|
|
25
|
+
};
|
|
26
|
+
interface Scheduler {
|
|
27
|
+
execute(fn: () => (void | Promise<undefined>)[]): void | Promise<undefined>;
|
|
28
|
+
}
|
|
29
|
+
export declare const AsyncScheduler: Scheduler;
|
|
30
|
+
export declare const SyncScheduler: Scheduler;
|
|
31
|
+
export declare class Subject<T, E = unknown, T2 = T> implements FullSubscriber<T, E>, Observable<T, E> {
|
|
32
|
+
#private;
|
|
33
|
+
private readonly scheduler;
|
|
34
|
+
get $(): Observable<T, E>;
|
|
35
|
+
get hot(): boolean;
|
|
36
|
+
get cold(): boolean;
|
|
37
|
+
constructor(scheduler?: Scheduler);
|
|
38
|
+
onWarm(fn: Function): void;
|
|
39
|
+
next(t: T | T2): void | Promise<undefined>;
|
|
40
|
+
error(e: E): void | Promise<undefined>;
|
|
41
|
+
complete(): void | Promise<undefined>;
|
|
42
|
+
subscribe(subscriber: Subscriber<T, E>): Subscription;
|
|
43
|
+
pipe<T1>(o1: Subscriber<T, E> & Observable<T1, E>): Observable<T1, E>;
|
|
44
|
+
pipe<T1, T2>(o1: Subscriber<T, E> & Observable<T1, E>, o2: Subscriber<T1, E> & Observable<T2, E>): Observable<T2, E>;
|
|
45
|
+
filter(fn: (t: T) => boolean): Observable<T, E>;
|
|
46
|
+
distinct(fn?: (t1: T, t2: T) => boolean): Observable<T, E>;
|
|
47
|
+
map<U>(fn: (t: T) => U): Observable<U, E>;
|
|
48
|
+
reduce<A>(fn: (acc: A, t: T) => A, init: A): Observable<A, E>;
|
|
49
|
+
replay(n: number): Observable<T, E>;
|
|
50
|
+
tap(s: Subscriber<T, E>): Observable<T, E>;
|
|
51
|
+
}
|
|
52
|
+
export declare class BehaviorSubject<T, E = unknown, T2 = T> extends Subject<T, E, T2> {
|
|
53
|
+
#private;
|
|
54
|
+
constructor(t: T, scheduler?: Scheduler);
|
|
55
|
+
next(t: T | T2): void | Promise<undefined>;
|
|
56
|
+
subscribe(subscriber: Subscriber<T, E>): Subscription;
|
|
57
|
+
get current(): T;
|
|
58
|
+
}
|
|
59
|
+
export declare class ReplaySubject<T, E = unknown> extends Subject<T, E> {
|
|
60
|
+
#private;
|
|
61
|
+
private readonly n;
|
|
62
|
+
constructor(n: number, scheduler?: Scheduler);
|
|
63
|
+
next(t: T): void | Promise<undefined>;
|
|
64
|
+
subscribe(subscriber: Subscriber<T, E>): Subscription;
|
|
65
|
+
}
|
|
66
|
+
export declare function eventListener<E extends Event>(): (Subject<E, unknown, E> | ((e: E) => void))[];
|
|
67
|
+
export declare class EventHandler<E extends Event> extends Subject<E> {
|
|
68
|
+
private readonly eventFn;
|
|
69
|
+
constructor(eventFn: (e: E) => void | Promise<undefined>);
|
|
70
|
+
next(e: E): void;
|
|
71
|
+
}
|
|
72
|
+
export declare const watch: <T, E>(logger?: Logger) => (observable: Observable<T, E>) => void;
|
|
73
|
+
declare class MapOperator<T, U, E> extends Subject<U, E, T> implements FullSubscriber<T, E>, Observable<U, E> {
|
|
74
|
+
private readonly mapFn;
|
|
75
|
+
constructor(mapFn: (t: T) => U);
|
|
76
|
+
next(t: T): void | Promise<undefined>;
|
|
77
|
+
}
|
|
78
|
+
declare class FilterOperator<T, E> extends Subject<T, E> implements FullSubscriber<T, E>, Observable<T, E> {
|
|
79
|
+
private readonly filterFn;
|
|
80
|
+
constructor(filterFn: (t: T) => boolean);
|
|
81
|
+
next(t: T): void | Promise<undefined>;
|
|
82
|
+
}
|
|
83
|
+
declare class DistinctOperator<T, E> extends Subject<T, E> implements FullSubscriber<T, E>, Observable<T, E> {
|
|
84
|
+
#private;
|
|
85
|
+
private readonly distinctFn;
|
|
86
|
+
constructor(distinctFn?: (t1: T, t2: T) => boolean);
|
|
87
|
+
next(t: T): void | Promise<undefined>;
|
|
88
|
+
}
|
|
89
|
+
declare class ReduceOperator<A, T, E> extends BehaviorSubject<A, E, T> {
|
|
90
|
+
private readonly fn;
|
|
91
|
+
constructor(fn: (acc: A, t: T) => A, init: A);
|
|
92
|
+
next(t: T): void | Promise<undefined>;
|
|
93
|
+
}
|
|
94
|
+
export declare class TakeUntilOperator<T, E> extends Subject<T, E> {
|
|
95
|
+
constructor(o: Observable<unknown, unknown>);
|
|
96
|
+
}
|
|
97
|
+
export declare class TapOperator<T, E> extends Subject<T, E> {
|
|
98
|
+
private readonly subscriber;
|
|
99
|
+
constructor(fn: Subscriber<T, E>);
|
|
100
|
+
next(t: T): void | Promise<undefined>;
|
|
101
|
+
error(e: E): void | Promise<undefined>;
|
|
102
|
+
complete(): void | Promise<undefined>;
|
|
103
|
+
}
|
|
104
|
+
declare class FirstOperator<T, E> extends Subject<T, E> {
|
|
105
|
+
next(t: T): void | Promise<undefined>;
|
|
106
|
+
}
|
|
107
|
+
declare class LastOperator<T, E = Error> extends Subject<T, E> {
|
|
108
|
+
#private;
|
|
109
|
+
next(t: T): void;
|
|
110
|
+
complete(): void | Promise<undefined>;
|
|
111
|
+
}
|
|
112
|
+
export declare const filter: <T, E>(fn: (t: T) => boolean) => FilterOperator<T, E>;
|
|
113
|
+
export declare const distinct: <T, E>(fn?: ((t1: T, t2: T) => boolean) | undefined) => DistinctOperator<T, E>;
|
|
114
|
+
export declare const first: <T, E>() => FirstOperator<T, E>;
|
|
115
|
+
export declare const last: <T, E>() => LastOperator<T, E>;
|
|
116
|
+
export declare const map: <T1, T2, E>(fn: (t: T1) => T2) => MapOperator<T1, T2, E>;
|
|
117
|
+
export declare const replay: <T, E>(n: number) => ReplaySubject<T, E>;
|
|
118
|
+
export declare const reduce: <A, T, E>(fn: (acc: A, t: T) => A, init: A) => ReduceOperator<A, T, E>;
|
|
119
|
+
export declare const takeUntil: <T, E>(o: Observable<unknown, unknown>) => TakeUntilOperator<T, E>;
|
|
120
|
+
export declare const tap: <T, E>(fn: Subscriber<T, E>) => TapOperator<T, E>;
|
|
121
|
+
export declare const operator: {
|
|
122
|
+
filter: <T, E>(fn: (t: T) => boolean) => FilterOperator<T, E>;
|
|
123
|
+
distinct: <T_1, E_1>(fn?: ((t1: T_1, t2: T_1) => boolean) | undefined) => DistinctOperator<T_1, E_1>;
|
|
124
|
+
first: <T_2, E_2>() => FirstOperator<T_2, E_2>;
|
|
125
|
+
last: <T_3, E_3>() => LastOperator<T_3, E_3>;
|
|
126
|
+
map: <T1, T2, E_4>(fn: (t: T1) => T2) => MapOperator<T1, T2, E_4>;
|
|
127
|
+
replay: <T_4, E_5>(n: number) => ReplaySubject<T_4, E_5>;
|
|
128
|
+
reduce: <A, T_5, E_6>(fn: (acc: A, t: T_5) => A, init: A) => ReduceOperator<A, T_5, E_6>;
|
|
129
|
+
takeUntil: <T_6, E_7>(o: Observable<unknown, unknown>) => TakeUntilOperator<T_6, E_7>;
|
|
130
|
+
tap: <T_7, E_8>(fn: Subscriber<T_7, E_8>) => TapOperator<T_7, E_8>;
|
|
131
|
+
};
|
|
132
|
+
export {};
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { DEFAULT_LOGGER } from "../log.js";
|
|
2
|
+
export const Observable = {
|
|
3
|
+
of(...ts) {
|
|
4
|
+
const subject = new Subject();
|
|
5
|
+
(async function next() {
|
|
6
|
+
if (subject.cold) {
|
|
7
|
+
subject.onWarm(next);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (ts.length === 0) {
|
|
11
|
+
subject.complete();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const t = ts.shift();
|
|
15
|
+
await subject.next(t);
|
|
16
|
+
next();
|
|
17
|
+
})();
|
|
18
|
+
return subject;
|
|
19
|
+
},
|
|
20
|
+
combineLatest(o1, o2) {
|
|
21
|
+
let latestSubject = new Subject();
|
|
22
|
+
let o1LatestSet = false;
|
|
23
|
+
let o1Latest;
|
|
24
|
+
let o2LatestSet = false;
|
|
25
|
+
let o2Latest;
|
|
26
|
+
function next() {
|
|
27
|
+
if (o1LatestSet && o2LatestSet) {
|
|
28
|
+
latestSubject.next([o1Latest, o2Latest]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function error(e) {
|
|
32
|
+
latestSubject.error(e);
|
|
33
|
+
}
|
|
34
|
+
function complete() {
|
|
35
|
+
latestSubject.complete();
|
|
36
|
+
o1sub.unsubscribe();
|
|
37
|
+
o2sub.unsubscribe();
|
|
38
|
+
}
|
|
39
|
+
let o1sub = o1.subscribe({
|
|
40
|
+
next(t) {
|
|
41
|
+
o1Latest = t;
|
|
42
|
+
o1LatestSet = true;
|
|
43
|
+
next();
|
|
44
|
+
},
|
|
45
|
+
error,
|
|
46
|
+
complete,
|
|
47
|
+
});
|
|
48
|
+
let o2sub = o2.subscribe({
|
|
49
|
+
next(t) {
|
|
50
|
+
o2Latest = t;
|
|
51
|
+
o2LatestSet = true;
|
|
52
|
+
next();
|
|
53
|
+
},
|
|
54
|
+
error,
|
|
55
|
+
complete,
|
|
56
|
+
});
|
|
57
|
+
return latestSubject;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
export const AsyncScheduler = {
|
|
61
|
+
execute(fn) {
|
|
62
|
+
return Promise.all(fn()).then(() => undefined);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
export const SyncScheduler = {
|
|
66
|
+
execute(fn) {
|
|
67
|
+
fn();
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
export class Subject {
|
|
71
|
+
scheduler;
|
|
72
|
+
#coldWaiters = new Set();
|
|
73
|
+
#subscribers = new Set();
|
|
74
|
+
#complete = false;
|
|
75
|
+
get $() {
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
get hot() {
|
|
79
|
+
return this.#subscribers.size > 0;
|
|
80
|
+
}
|
|
81
|
+
get cold() {
|
|
82
|
+
return !this.hot;
|
|
83
|
+
}
|
|
84
|
+
constructor(scheduler = AsyncScheduler) {
|
|
85
|
+
this.scheduler = scheduler;
|
|
86
|
+
}
|
|
87
|
+
onWarm(fn) {
|
|
88
|
+
if (this.cold)
|
|
89
|
+
this.#coldWaiters.add(fn);
|
|
90
|
+
}
|
|
91
|
+
next(t) {
|
|
92
|
+
if (this.#complete)
|
|
93
|
+
throw new Error("Cannot call next on a completed subject");
|
|
94
|
+
return this.scheduler.execute(() => [...this.#subscribers].map((s) => s.next?.(t)));
|
|
95
|
+
}
|
|
96
|
+
error(e) {
|
|
97
|
+
if (this.#complete)
|
|
98
|
+
throw new Error("Cannot call error on a completed subject");
|
|
99
|
+
return this.scheduler.execute(() => [...this.#subscribers].map((s) => s.error?.(e)));
|
|
100
|
+
}
|
|
101
|
+
complete() {
|
|
102
|
+
if (this.#complete)
|
|
103
|
+
throw new Error("Cannot call complete on a completed subject");
|
|
104
|
+
this.#complete = true;
|
|
105
|
+
const finished = this.scheduler.execute(() => [...this.#subscribers].map((s) => s.complete?.()));
|
|
106
|
+
this.#subscribers.clear(); // Free subscribers for garbage collection
|
|
107
|
+
return finished;
|
|
108
|
+
}
|
|
109
|
+
subscribe(subscriber) {
|
|
110
|
+
if (this.#complete)
|
|
111
|
+
throw new Error("Cannot call subscribe on a completed subject");
|
|
112
|
+
if (subscriber instanceof Function) {
|
|
113
|
+
subscriber = { next: subscriber };
|
|
114
|
+
}
|
|
115
|
+
this.#subscribers.add(subscriber);
|
|
116
|
+
[...this.#coldWaiters].forEach((w) => w());
|
|
117
|
+
this.#coldWaiters.clear();
|
|
118
|
+
return {
|
|
119
|
+
unsubscribe: () => this.#subscribers.delete(subscriber),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
pipe(...os) {
|
|
123
|
+
this.subscribe(os[0]);
|
|
124
|
+
for (let i = 1; i < os.length; i++) {
|
|
125
|
+
os[i - 1].subscribe(os[i]);
|
|
126
|
+
}
|
|
127
|
+
return os[os.length - 1];
|
|
128
|
+
}
|
|
129
|
+
filter(fn) {
|
|
130
|
+
return this.pipe(operator.filter(fn));
|
|
131
|
+
}
|
|
132
|
+
distinct(fn = Object.is) {
|
|
133
|
+
return this.pipe(operator.distinct(fn));
|
|
134
|
+
}
|
|
135
|
+
map(fn) {
|
|
136
|
+
return this.pipe(operator.map(fn));
|
|
137
|
+
}
|
|
138
|
+
reduce(fn, init) {
|
|
139
|
+
return this.pipe(operator.reduce(fn, init));
|
|
140
|
+
}
|
|
141
|
+
replay(n) {
|
|
142
|
+
return this.pipe(operator.replay(n));
|
|
143
|
+
}
|
|
144
|
+
tap(s) {
|
|
145
|
+
return this.pipe(operator.tap(s));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export class BehaviorSubject extends Subject {
|
|
149
|
+
#current;
|
|
150
|
+
constructor(t, scheduler) {
|
|
151
|
+
super(scheduler);
|
|
152
|
+
this.#current = t;
|
|
153
|
+
}
|
|
154
|
+
next(t) {
|
|
155
|
+
this.#current = t;
|
|
156
|
+
return super.next(t);
|
|
157
|
+
}
|
|
158
|
+
subscribe(subscriber) {
|
|
159
|
+
if (subscriber instanceof Function) {
|
|
160
|
+
subscriber = { next: subscriber };
|
|
161
|
+
}
|
|
162
|
+
subscriber.next?.(this.#current);
|
|
163
|
+
return super.subscribe(subscriber);
|
|
164
|
+
}
|
|
165
|
+
get current() {
|
|
166
|
+
return this.#current;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
export class ReplaySubject extends Subject {
|
|
170
|
+
n;
|
|
171
|
+
#history = [];
|
|
172
|
+
constructor(n, scheduler) {
|
|
173
|
+
super(scheduler);
|
|
174
|
+
this.n = n;
|
|
175
|
+
}
|
|
176
|
+
next(t) {
|
|
177
|
+
this.#history.push(t);
|
|
178
|
+
if (this.#history.length > this.n) {
|
|
179
|
+
this.#history.shift();
|
|
180
|
+
}
|
|
181
|
+
return super.next(t);
|
|
182
|
+
}
|
|
183
|
+
subscribe(subscriber) {
|
|
184
|
+
if (subscriber instanceof Function) {
|
|
185
|
+
subscriber = { next: subscriber };
|
|
186
|
+
}
|
|
187
|
+
const history = [...this.#history];
|
|
188
|
+
(function send() {
|
|
189
|
+
if (history.length == 0)
|
|
190
|
+
return;
|
|
191
|
+
const t = history.shift();
|
|
192
|
+
subscriber.next?.(t);
|
|
193
|
+
new Promise(send);
|
|
194
|
+
})();
|
|
195
|
+
return super.subscribe(subscriber);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
export function eventListener() {
|
|
199
|
+
const observable = new Subject();
|
|
200
|
+
function listener(e) {
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
observable.next(e);
|
|
203
|
+
}
|
|
204
|
+
return [observable, listener];
|
|
205
|
+
}
|
|
206
|
+
export class EventHandler extends Subject {
|
|
207
|
+
eventFn;
|
|
208
|
+
constructor(eventFn) {
|
|
209
|
+
super();
|
|
210
|
+
this.eventFn = eventFn;
|
|
211
|
+
}
|
|
212
|
+
next(e) {
|
|
213
|
+
e.preventDefault();
|
|
214
|
+
super.next(e);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
export const watch = (logger = DEFAULT_LOGGER) => (observable) => {
|
|
218
|
+
observable.tap({
|
|
219
|
+
next(t) {
|
|
220
|
+
logger.info(t);
|
|
221
|
+
},
|
|
222
|
+
complete() {
|
|
223
|
+
logger.info("Observable completed");
|
|
224
|
+
},
|
|
225
|
+
error(e) {
|
|
226
|
+
logger.warn(e);
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
class MapOperator extends Subject {
|
|
231
|
+
mapFn;
|
|
232
|
+
constructor(mapFn) {
|
|
233
|
+
super();
|
|
234
|
+
this.mapFn = mapFn;
|
|
235
|
+
}
|
|
236
|
+
next(t) {
|
|
237
|
+
return super.next(this.mapFn(t));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
class FilterOperator extends Subject {
|
|
241
|
+
filterFn;
|
|
242
|
+
constructor(filterFn) {
|
|
243
|
+
super();
|
|
244
|
+
this.filterFn = filterFn;
|
|
245
|
+
}
|
|
246
|
+
next(t) {
|
|
247
|
+
return this.filterFn(t) ? super.next(t) : undefined;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
class DistinctOperator extends Subject {
|
|
251
|
+
distinctFn;
|
|
252
|
+
#prior = undefined;
|
|
253
|
+
constructor(distinctFn = Object.is) {
|
|
254
|
+
super();
|
|
255
|
+
this.distinctFn = distinctFn;
|
|
256
|
+
}
|
|
257
|
+
next(t) {
|
|
258
|
+
if (this.#prior === undefined) {
|
|
259
|
+
this.#prior = t;
|
|
260
|
+
return super.next(t);
|
|
261
|
+
}
|
|
262
|
+
const same = this.distinctFn(this.#prior, t);
|
|
263
|
+
if (!same) {
|
|
264
|
+
this.#prior = t;
|
|
265
|
+
return super.next(t);
|
|
266
|
+
}
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
class ReduceOperator extends BehaviorSubject {
|
|
271
|
+
fn;
|
|
272
|
+
constructor(fn, init) {
|
|
273
|
+
super(init);
|
|
274
|
+
this.fn = fn;
|
|
275
|
+
}
|
|
276
|
+
next(t) {
|
|
277
|
+
return super.next(this.fn(this.current, t));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
export class TakeUntilOperator extends Subject {
|
|
281
|
+
constructor(o) {
|
|
282
|
+
super();
|
|
283
|
+
o.subscribe(() => this.complete());
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
export class TapOperator extends Subject {
|
|
287
|
+
subscriber;
|
|
288
|
+
constructor(fn) {
|
|
289
|
+
super();
|
|
290
|
+
this.subscriber = fn instanceof Function ? { next: fn } : fn;
|
|
291
|
+
}
|
|
292
|
+
next(t) {
|
|
293
|
+
this.subscriber.next?.(t);
|
|
294
|
+
return super.next(t);
|
|
295
|
+
}
|
|
296
|
+
error(e) {
|
|
297
|
+
this.subscriber.error?.(e);
|
|
298
|
+
return super.error(e);
|
|
299
|
+
}
|
|
300
|
+
complete() {
|
|
301
|
+
this.subscriber.complete?.();
|
|
302
|
+
return super.complete();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
class FirstOperator extends Subject {
|
|
306
|
+
next(t) {
|
|
307
|
+
const next = super.next(t);
|
|
308
|
+
this.complete();
|
|
309
|
+
return next;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
class LastOperator extends Subject {
|
|
313
|
+
#latest;
|
|
314
|
+
next(t) {
|
|
315
|
+
this.#latest = t;
|
|
316
|
+
}
|
|
317
|
+
complete() {
|
|
318
|
+
if (this.#latest !== undefined) {
|
|
319
|
+
super.next(this.#latest);
|
|
320
|
+
}
|
|
321
|
+
return super.complete();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
export const filter = (fn) => new FilterOperator(fn);
|
|
325
|
+
export const distinct = (fn) => new DistinctOperator(fn ?? Object.is);
|
|
326
|
+
export const first = () => new FirstOperator();
|
|
327
|
+
export const last = () => new LastOperator();
|
|
328
|
+
export const map = (fn) => new MapOperator(fn);
|
|
329
|
+
export const replay = (n) => new ReplaySubject(n);
|
|
330
|
+
export const reduce = (fn, init) => new ReduceOperator(fn, init);
|
|
331
|
+
export const takeUntil = (o) => new TakeUntilOperator(o);
|
|
332
|
+
export const tap = (fn) => new TapOperator(fn);
|
|
333
|
+
export const operator = {
|
|
334
|
+
filter,
|
|
335
|
+
distinct,
|
|
336
|
+
first,
|
|
337
|
+
last,
|
|
338
|
+
map,
|
|
339
|
+
replay,
|
|
340
|
+
reduce,
|
|
341
|
+
takeUntil,
|
|
342
|
+
tap,
|
|
343
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, expect, it } from "../scope/index.js";
|
|
2
|
+
import { Observable, Subject, filter, map } 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
|
+
it("builds an observable of items", async () => {
|
|
20
|
+
const stream = Observable.of(2, 4, 8, 16);
|
|
21
|
+
let values = [];
|
|
22
|
+
await new Promise((resolve) => {
|
|
23
|
+
stream.subscribe({
|
|
24
|
+
next: (n) => {
|
|
25
|
+
values.unshift(n);
|
|
26
|
+
},
|
|
27
|
+
complete: () => {
|
|
28
|
+
resolve();
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
expect(values).toEqual([16, 8, 4, 2]);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe("pipes", () => {
|
|
36
|
+
it("runs a pipe", async () => {
|
|
37
|
+
const subject = new Subject();
|
|
38
|
+
let resolved = 0;
|
|
39
|
+
const inflate = (i) => (n) => n + i;
|
|
40
|
+
const biggerThan = (i) => (n) => n > i;
|
|
41
|
+
const assign = (n) => {
|
|
42
|
+
resolved = n;
|
|
43
|
+
};
|
|
44
|
+
subject.pipe(map(inflate(22)), filter(biggerThan(70))).subscribe(assign);
|
|
45
|
+
expect(resolved).toBe(0);
|
|
46
|
+
await subject.next(42);
|
|
47
|
+
expect(resolved).toBe(0);
|
|
48
|
+
await subject.next(50);
|
|
49
|
+
expect(resolved).toBe(72);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe("Subject", () => {
|
|
53
|
+
it("is callable", async () => {
|
|
54
|
+
const subject = new Subject();
|
|
55
|
+
let resolved = 0;
|
|
56
|
+
subject.subscribe((n) => {
|
|
57
|
+
resolved = n;
|
|
58
|
+
});
|
|
59
|
+
await subject.next(42);
|
|
60
|
+
expect(resolved).toBe(42);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function range(start: number, end: number, stride?: number): number[];
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +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;
|