grainjs 1.0.2 → 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.
- package/README.md +23 -71
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/PriorityQueue.d.ts +1 -1
- package/dist/cjs/lib/_computed_queue.js +3 -3
- package/dist/cjs/lib/_computed_queue.js.map +1 -1
- package/dist/cjs/lib/binding.d.ts +11 -4
- package/dist/cjs/lib/binding.js +5 -5
- package/dist/cjs/lib/binding.js.map +1 -1
- package/dist/cjs/lib/computed.d.ts +49 -28
- package/dist/cjs/lib/computed.js +38 -52
- package/dist/cjs/lib/computed.js.map +1 -1
- package/dist/cjs/lib/dispose.d.ts +109 -96
- package/dist/cjs/lib/dispose.js +106 -80
- package/dist/cjs/lib/dispose.js.map +1 -1
- package/dist/cjs/lib/dom.d.ts +38 -18
- package/dist/cjs/lib/dom.js +44 -20
- package/dist/cjs/lib/dom.js.map +1 -1
- package/dist/cjs/lib/domComponent.d.ts +56 -48
- package/dist/cjs/lib/domComponent.js +66 -1
- package/dist/cjs/lib/domComponent.js.map +1 -1
- package/dist/cjs/lib/domComputed.d.ts +31 -21
- package/dist/cjs/lib/domComputed.js +14 -11
- package/dist/cjs/lib/domComputed.js.map +1 -1
- package/dist/cjs/lib/domDispose.d.ts +27 -12
- package/dist/cjs/lib/domDispose.js +26 -11
- package/dist/cjs/lib/domDispose.js.map +1 -1
- package/dist/cjs/lib/domForEach.d.ts +4 -3
- package/dist/cjs/lib/domForEach.js +10 -9
- package/dist/cjs/lib/domForEach.js.map +1 -1
- package/dist/cjs/lib/domImpl.d.ts +33 -10
- package/dist/cjs/lib/domImpl.js +28 -9
- package/dist/cjs/lib/domImpl.js.map +1 -1
- package/dist/cjs/lib/domMethods.d.ts +93 -47
- package/dist/cjs/lib/domMethods.js +88 -46
- package/dist/cjs/lib/domMethods.js.map +1 -1
- package/dist/cjs/lib/domevent.d.ts +87 -62
- package/dist/cjs/lib/domevent.js +84 -59
- package/dist/cjs/lib/domevent.js.map +1 -1
- package/dist/cjs/lib/emit.d.ts +62 -32
- package/dist/cjs/lib/emit.js +67 -53
- package/dist/cjs/lib/emit.js.map +1 -1
- package/dist/cjs/lib/kowrap.d.ts +6 -3
- package/dist/cjs/lib/kowrap.js +6 -3
- package/dist/cjs/lib/kowrap.js.map +1 -1
- package/dist/cjs/lib/obsArray.d.ts +91 -53
- package/dist/cjs/lib/obsArray.js +87 -55
- package/dist/cjs/lib/obsArray.js.map +1 -1
- package/dist/cjs/lib/observable.d.ts +25 -15
- package/dist/cjs/lib/observable.js +29 -18
- package/dist/cjs/lib/observable.js.map +1 -1
- package/dist/cjs/lib/pureComputed.d.ts +12 -15
- package/dist/cjs/lib/pureComputed.js +15 -18
- package/dist/cjs/lib/pureComputed.js.map +1 -1
- package/dist/cjs/lib/styled.d.ts +78 -61
- package/dist/cjs/lib/styled.js +26 -79
- package/dist/cjs/lib/styled.js.map +1 -1
- package/dist/cjs/lib/subscribe.d.ts +41 -37
- package/dist/cjs/lib/subscribe.js +31 -40
- package/dist/cjs/lib/subscribe.js.map +1 -1
- package/dist/cjs/lib/util.js +1 -0
- package/dist/cjs/lib/util.js.map +1 -1
- package/dist/cjs/lib/widgets/input.d.ts +3 -1
- package/dist/cjs/lib/widgets/input.js +6 -4
- package/dist/cjs/lib/widgets/input.js.map +1 -1
- package/dist/cjs/lib/widgets/select.d.ts +4 -2
- package/dist/cjs/lib/widgets/select.js +7 -5
- package/dist/cjs/lib/widgets/select.js.map +1 -1
- package/dist/esm/lib/_computed_queue.js +3 -3
- package/dist/esm/lib/_computed_queue.js.map +1 -1
- package/dist/esm/lib/binding.js +2 -2
- package/dist/esm/lib/binding.js.map +1 -1
- package/dist/esm/lib/computed.js +36 -50
- package/dist/esm/lib/computed.js.map +1 -1
- package/dist/esm/lib/dispose.js +104 -78
- package/dist/esm/lib/dispose.js.map +1 -1
- package/dist/esm/lib/dom.js +38 -18
- package/dist/esm/lib/dom.js.map +1 -1
- package/dist/esm/lib/domComponent.js +65 -0
- package/dist/esm/lib/domComponent.js.map +1 -1
- package/dist/esm/lib/domComputed.js +10 -7
- package/dist/esm/lib/domComputed.js.map +1 -1
- package/dist/esm/lib/domDispose.js +26 -11
- package/dist/esm/lib/domDispose.js.map +1 -1
- package/dist/esm/lib/domForEach.js +3 -2
- package/dist/esm/lib/domForEach.js.map +1 -1
- package/dist/esm/lib/domImpl.js +26 -7
- package/dist/esm/lib/domImpl.js.map +1 -1
- package/dist/esm/lib/domMethods.js +77 -35
- package/dist/esm/lib/domMethods.js.map +1 -1
- package/dist/esm/lib/domevent.js +84 -59
- package/dist/esm/lib/domevent.js.map +1 -1
- package/dist/esm/lib/emit.js +67 -53
- package/dist/esm/lib/emit.js.map +1 -1
- package/dist/esm/lib/kowrap.js +5 -2
- package/dist/esm/lib/kowrap.js.map +1 -1
- package/dist/esm/lib/obsArray.js +82 -50
- package/dist/esm/lib/obsArray.js.map +1 -1
- package/dist/esm/lib/observable.js +26 -15
- package/dist/esm/lib/observable.js.map +1 -1
- package/dist/esm/lib/pureComputed.js +15 -18
- package/dist/esm/lib/pureComputed.js.map +1 -1
- package/dist/esm/lib/styled.js +24 -77
- package/dist/esm/lib/styled.js.map +1 -1
- package/dist/esm/lib/subscribe.js +27 -36
- package/dist/esm/lib/subscribe.js.map +1 -1
- package/dist/esm/lib/util.js +1 -0
- package/dist/esm/lib/util.js.map +1 -1
- package/dist/esm/lib/widgets/input.js +3 -1
- package/dist/esm/lib/widgets/input.js.map +1 -1
- package/dist/esm/lib/widgets/select.js +3 -1
- package/dist/esm/lib/widgets/select.js.map +1 -1
- package/dist/grain-full.debug.js +2146 -3062
- package/dist/grain-full.debug.js.map +7 -0
- package/dist/grain-full.min.js +6 -2
- package/dist/grain-full.min.js.map +7 -1
- package/lib/binding.ts +9 -2
- package/lib/computed.ts +56 -56
- package/lib/dispose.ts +110 -85
- package/lib/dom.ts +39 -20
- package/lib/domComponent.ts +66 -57
- package/lib/domComputed.ts +29 -19
- package/lib/domDispose.ts +28 -11
- package/lib/domForEach.ts +7 -3
- package/lib/domImpl.ts +30 -7
- package/lib/domMethods.ts +101 -46
- package/lib/domevent.ts +85 -60
- package/lib/emit.ts +64 -50
- package/lib/kowrap.ts +5 -2
- package/lib/obsArray.ts +89 -54
- package/lib/observable.ts +26 -15
- package/lib/pureComputed.ts +16 -22
- package/lib/styled.ts +85 -71
- package/lib/subscribe.ts +41 -45
- package/lib/util.ts +1 -0
- package/lib/widgets/input.ts +3 -1
- package/lib/widgets/select.ts +3 -1
- package/package.json +38 -27
|
@@ -1,40 +1,47 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* subscribe.js implements subscriptions to several observables at once.
|
|
3
|
-
*
|
|
4
|
-
* E.g. if we have some existing observables (which may be instances of `computed`),
|
|
5
|
-
* we can subscribe to them explicitly:
|
|
6
|
-
* let obs1 = observable(5), obs2 = observable(12);
|
|
7
|
-
* subscribe(obs1, obs2, (use, v1, v2) => console.log(v1, v2));
|
|
8
|
-
*
|
|
9
|
-
* or implicitly by using `use(obs)` function, which allows dynamic subscriptions:
|
|
10
|
-
* subscribe(use => console.log(use(obs1), use(obs2)));
|
|
11
|
-
*
|
|
12
|
-
* In either case, if obs1 or obs2 is changed, the callbacks will get called automatically.
|
|
13
|
-
*
|
|
14
|
-
* Creating a subscription allows any number of dependencies to be specified explicitly, and their
|
|
15
|
-
* values will be passed to the callback(). These may be combined with automatic dependencies
|
|
16
|
-
* detected using use(). Note that constructor dependencies have less overhead.
|
|
17
|
-
*
|
|
18
|
-
* subscribe(...deps, ((use, ...depValues) => READ_CALLBACK));
|
|
19
|
-
*/
|
|
20
1
|
import { DepItem } from './_computed_queue';
|
|
21
2
|
import { IDisposableOwner } from './dispose';
|
|
22
3
|
import { Listener } from './emit';
|
|
23
4
|
import { IKnockoutReadObservable } from './kowrap';
|
|
24
5
|
import { BaseObservable as Obs } from './observable';
|
|
25
6
|
export interface ISubscribableObs {
|
|
7
|
+
/** @internal */
|
|
26
8
|
_getDepItem(): DepItem | null;
|
|
27
9
|
addListener(callback: (val: any, prev: any) => void, optContext?: object): Listener;
|
|
28
10
|
get(): any;
|
|
29
11
|
}
|
|
30
|
-
export
|
|
31
|
-
export
|
|
12
|
+
export type ISubscribable = ISubscribableObs | IKnockoutReadObservable<any>;
|
|
13
|
+
export type InferUseType<TObs extends Obs<any> | IKnockoutReadObservable<any>> = TObs extends Obs<infer T> ? T : TObs extends {
|
|
32
14
|
peek(): infer U;
|
|
33
15
|
} ? U : never;
|
|
34
|
-
export
|
|
16
|
+
export type UseCB = <TObs extends Obs<any> | IKnockoutReadObservable<any>>(obs: TObs) => InferUseType<TObs>;
|
|
35
17
|
export interface UseCBOwner extends UseCB {
|
|
36
18
|
owner: IDisposableOwner;
|
|
37
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* `Subscription` allows subscribing to several observables at once. It's the foundation for a
|
|
22
|
+
* `Computed`, but may also be used directly.
|
|
23
|
+
*
|
|
24
|
+
* E.g. if we have some existing observables (which may be instances of `Computed`),
|
|
25
|
+
* we can subscribe to them explicitly:
|
|
26
|
+
* ```ts
|
|
27
|
+
* const obs1 = observable(5), obs2 = observable(12);
|
|
28
|
+
* subscribe(obs1, obs2, (use, v1, v2) => console.log(v1, v2));
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* or implicitly by using `use(obs)` function, which allows dynamic subscriptions:
|
|
32
|
+
* ```ts
|
|
33
|
+
* subscribe(use => console.log(use(obs1), use(obs2)));
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* In either case, if `obs1` or `obs2` is changed, the callbacks will get called automatically.
|
|
37
|
+
*
|
|
38
|
+
* Creating a subscription allows any number of dependencies to be specified explicitly, and their
|
|
39
|
+
* values will be passed to the `callback`. These may be combined with automatic dependencies
|
|
40
|
+
* detected using `use()`. Note that constructor dependencies have less overhead.
|
|
41
|
+
* ```ts
|
|
42
|
+
* subscribe(...deps, ((use, ...depValues) => READ_CALLBACK));
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
38
45
|
export declare class Subscription {
|
|
39
46
|
private readonly _depItem;
|
|
40
47
|
private readonly _dependencies;
|
|
@@ -42,11 +49,6 @@ export declare class Subscription {
|
|
|
42
49
|
private _dynDeps;
|
|
43
50
|
private _callback;
|
|
44
51
|
private _useFunc;
|
|
45
|
-
/**
|
|
46
|
-
* Internal constructor for a Subscription. You should use subscribe() function instead.
|
|
47
|
-
* The last owner argument is used by computed() to make itself available as the .owner property
|
|
48
|
-
* of the 'use' function that gets passed to the callback.
|
|
49
|
-
*/
|
|
50
52
|
constructor(callback: (use: UseCB, ...args: any[]) => void, dependencies: ReadonlyArray<ISubscribable>, owner?: any);
|
|
51
53
|
/**
|
|
52
54
|
* Disposes the computed, unsubscribing it from all observables it depends on.
|
|
@@ -54,38 +56,40 @@ export declare class Subscription {
|
|
|
54
56
|
dispose(): void;
|
|
55
57
|
/**
|
|
56
58
|
* For use by computed(): returns this subscription's hook into the _computed_queue.
|
|
59
|
+
* @internal
|
|
57
60
|
*/
|
|
58
61
|
_getDepItem(): DepItem;
|
|
59
62
|
/**
|
|
60
|
-
* @private
|
|
61
63
|
* Gets called when the callback calls `use(obs)` for an observable. It creates a
|
|
62
64
|
* subscription to `obs` if one doesn't yet exist.
|
|
63
|
-
* @param
|
|
65
|
+
* @param obs - The observable being used as a dependency.
|
|
64
66
|
*/
|
|
65
67
|
private _useDependency;
|
|
66
68
|
/**
|
|
67
|
-
* @private
|
|
68
69
|
* Calls the callback() with appropriate args, and updates subscriptions when it is done.
|
|
69
70
|
* I.e. adds dynamic subscriptions created via `use(obs)`, and disposes those no longer used.
|
|
70
71
|
*/
|
|
71
72
|
private _evaluate;
|
|
72
73
|
/**
|
|
73
|
-
* @private
|
|
74
74
|
* Subscribes this computed to another observable that it depends on.
|
|
75
|
-
* @param
|
|
76
|
-
* @returns
|
|
75
|
+
* @param obs - The observable to subscribe to.
|
|
76
|
+
* @returns Listener object.
|
|
77
77
|
*/
|
|
78
78
|
private _subscribeTo;
|
|
79
79
|
/**
|
|
80
|
-
* @private
|
|
81
80
|
* Adds this item to the recompute queue.
|
|
82
81
|
*/
|
|
83
82
|
private _enqueue;
|
|
84
83
|
}
|
|
85
84
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
85
|
+
* Creates a new Subscription.
|
|
86
|
+
* @param observables - The initial params, of which there may be zero or more, are
|
|
87
|
+
* observables on which this computed depends. When any of them change, the `callback`
|
|
88
|
+
* will be called with the values of these observables as arguments.
|
|
89
|
+
* @param callback - will be called with arguments `(use, ...values)`, i.e. the
|
|
90
|
+
* `use` function and values for all of the `...observables` that precede this argument.
|
|
91
|
+
* This callback is called immediately, and whenever any dependency changes.
|
|
92
|
+
* @returns The new `Subscription` which may be disposed to unsubscribe.
|
|
89
93
|
*/
|
|
90
94
|
export declare function subscribe(cb: (use: UseCB) => void): Subscription;
|
|
91
95
|
export declare function subscribe<A>(a: Obs<A>, cb: (use: UseCB, a: A) => void): Subscription;
|
|
@@ -1,35 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscribe = exports.Subscription = void 0;
|
|
4
|
+
const _computed_queue_1 = require("./_computed_queue");
|
|
5
|
+
const kowrap_1 = require("./kowrap");
|
|
6
|
+
// Constant empty array, which we use to avoid allocating new read-only empty arrays.
|
|
7
|
+
const emptyArray = [];
|
|
2
8
|
/**
|
|
3
|
-
*
|
|
9
|
+
* `Subscription` allows subscribing to several observables at once. It's the foundation for a
|
|
10
|
+
* `Computed`, but may also be used directly.
|
|
4
11
|
*
|
|
5
|
-
* E.g. if we have some existing observables (which may be instances of `
|
|
12
|
+
* E.g. if we have some existing observables (which may be instances of `Computed`),
|
|
6
13
|
* we can subscribe to them explicitly:
|
|
7
|
-
*
|
|
8
|
-
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const obs1 = observable(5), obs2 = observable(12);
|
|
16
|
+
* subscribe(obs1, obs2, (use, v1, v2) => console.log(v1, v2));
|
|
17
|
+
* ```
|
|
9
18
|
*
|
|
10
19
|
* or implicitly by using `use(obs)` function, which allows dynamic subscriptions:
|
|
11
|
-
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* subscribe(use => console.log(use(obs1), use(obs2)));
|
|
22
|
+
* ```
|
|
12
23
|
*
|
|
13
|
-
* In either case, if obs1 or obs2 is changed, the callbacks will get called automatically.
|
|
24
|
+
* In either case, if `obs1` or `obs2` is changed, the callbacks will get called automatically.
|
|
14
25
|
*
|
|
15
26
|
* Creating a subscription allows any number of dependencies to be specified explicitly, and their
|
|
16
|
-
* values will be passed to the callback
|
|
17
|
-
* detected using use()
|
|
18
|
-
*
|
|
19
|
-
*
|
|
27
|
+
* values will be passed to the `callback`. These may be combined with automatic dependencies
|
|
28
|
+
* detected using `use()`. Note that constructor dependencies have less overhead.
|
|
29
|
+
* ```ts
|
|
30
|
+
* subscribe(...deps, ((use, ...depValues) => READ_CALLBACK));
|
|
31
|
+
* ```
|
|
20
32
|
*/
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.subscribe = exports.Subscription = void 0;
|
|
23
|
-
const _computed_queue_1 = require("./_computed_queue");
|
|
24
|
-
const kowrap_1 = require("./kowrap");
|
|
25
|
-
// Constant empty array, which we use to avoid allocating new read-only empty arrays.
|
|
26
|
-
const emptyArray = [];
|
|
27
33
|
class Subscription {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* of the 'use' function that gets passed to the callback.
|
|
32
|
-
*/
|
|
34
|
+
// Internal constructor for a Subscription. You should use subscribe() function instead.
|
|
35
|
+
// The last owner argument is used by computed() to make itself available as the .owner property
|
|
36
|
+
// of the 'use' function that gets passed to the callback.
|
|
33
37
|
constructor(callback, dependencies, owner) {
|
|
34
38
|
this._depItem = new _computed_queue_1.DepItem(this._evaluate, this);
|
|
35
39
|
this._dependencies = dependencies.length > 0 ? dependencies : emptyArray;
|
|
@@ -56,16 +60,16 @@ class Subscription {
|
|
|
56
60
|
}
|
|
57
61
|
/**
|
|
58
62
|
* For use by computed(): returns this subscription's hook into the _computed_queue.
|
|
63
|
+
* @internal
|
|
59
64
|
*/
|
|
60
65
|
_getDepItem() { return this._depItem; }
|
|
61
66
|
/**
|
|
62
|
-
* @private
|
|
63
67
|
* Gets called when the callback calls `use(obs)` for an observable. It creates a
|
|
64
68
|
* subscription to `obs` if one doesn't yet exist.
|
|
65
|
-
* @param
|
|
69
|
+
* @param obs - The observable being used as a dependency.
|
|
66
70
|
*/
|
|
67
71
|
_useDependency(_obs) {
|
|
68
|
-
const obs = ('_getDepItem' in _obs) ? _obs : kowrap_1.fromKo(_obs);
|
|
72
|
+
const obs = ('_getDepItem' in _obs) ? _obs : (0, kowrap_1.fromKo)(_obs);
|
|
69
73
|
let listener = this._dynDeps.get(obs);
|
|
70
74
|
if (!listener) {
|
|
71
75
|
listener = this._subscribeTo(obs);
|
|
@@ -76,7 +80,6 @@ class Subscription {
|
|
|
76
80
|
return obs.get();
|
|
77
81
|
}
|
|
78
82
|
/**
|
|
79
|
-
* @private
|
|
80
83
|
* Calls the callback() with appropriate args, and updates subscriptions when it is done.
|
|
81
84
|
* I.e. adds dynamic subscriptions created via `use(obs)`, and disposes those no longer used.
|
|
82
85
|
*/
|
|
@@ -106,17 +109,15 @@ class Subscription {
|
|
|
106
109
|
}
|
|
107
110
|
}
|
|
108
111
|
/**
|
|
109
|
-
* @private
|
|
110
112
|
* Subscribes this computed to another observable that it depends on.
|
|
111
|
-
* @param
|
|
112
|
-
* @returns
|
|
113
|
+
* @param obs - The observable to subscribe to.
|
|
114
|
+
* @returns Listener object.
|
|
113
115
|
*/
|
|
114
116
|
_subscribeTo(_obs) {
|
|
115
|
-
const obs = ('_getDepItem' in _obs) ? _obs : kowrap_1.fromKo(_obs);
|
|
117
|
+
const obs = ('_getDepItem' in _obs) ? _obs : (0, kowrap_1.fromKo)(_obs);
|
|
116
118
|
return obs.addListener(this._enqueue, this);
|
|
117
119
|
}
|
|
118
120
|
/**
|
|
119
|
-
* @private
|
|
120
121
|
* Adds this item to the recompute queue.
|
|
121
122
|
*/
|
|
122
123
|
_enqueue() {
|
|
@@ -124,16 +125,6 @@ class Subscription {
|
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
exports.Subscription = Subscription;
|
|
127
|
-
/**
|
|
128
|
-
* Creates a new Subscription.
|
|
129
|
-
* @param {Observable} ...observables: The initial params, of which there may be zero or more, are
|
|
130
|
-
* observables on which this computed depends. When any of them change, the callback()
|
|
131
|
-
* will be called with the values of these observables as arguments.
|
|
132
|
-
* @param {Function} callback: will be called with arguments (use, ...values), i.e. the
|
|
133
|
-
* `use` function and values for all of the ...observables that precede this argument.
|
|
134
|
-
* This callback is called immediately, and whenever any dependency changes.
|
|
135
|
-
* @returns {Subscription} The new subscription which may be disposed to unsubscribe.
|
|
136
|
-
*/
|
|
137
128
|
function subscribe(...args) {
|
|
138
129
|
const cb = args.pop();
|
|
139
130
|
// The cast helps ensure that Observable is compatible with ISubscribable abstraction that we use.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe.js","sourceRoot":"","sources":["../../../lib/subscribe.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"subscribe.js","sourceRoot":"","sources":["../../../lib/subscribe.ts"],"names":[],"mappings":";;;AAAA,uDAA0C;AAG1C,qCAAyD;AA6BzD,qFAAqF;AACrF,MAAM,UAAU,GAAuB,EAAE,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,YAAY;IAQvB,wFAAwF;IACxF,gGAAgG;IAChG,0DAA0D;IAC1D,YAAY,QAA8C,EAAE,YAA0C,EAAE,KAAW;QACjH,IAAI,CAAC,QAAQ,GAAG,IAAI,yBAAO,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI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ACL,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;oBAC1B,QAAQ,CAAC,OAAO,EAAE,CAAC;iBACpB;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAED;;;;OAIG;IACK,YAAY,CAAC,IAAmB;QACtC,MAAM,GAAG,GAAG,CAAC,aAAa,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC;QAC1D,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACK,QAAQ;QACd,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;CACF;AApGD,oCAoGC;AAkCD,SAAgB,SAAS,CAAC,GAAG,IAAW;IACtC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACtB,kGAAkG;IAClG,OAAO,IAAI,YAAY,CAAC,EAAE,EAAE,IAAuB,CAAC,CAAC;AACvD,CAAC;AAJD,8BAIC"}
|
package/dist/cjs/lib/util.js
CHANGED
package/dist/cjs/lib/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../lib/util.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../lib/util.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;AAElC;;;GAGG;AACH,SAAgB,KAAK,CAAI,IAA2B,EAAE,CAAQ;IAC5D,QAAQ,CAAC,CAAC,MAAM,EAAE;QAChB,KAAK,CAAC,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;QAC5B,KAAK,CAAC,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAChC,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every change to the observable will affect the input element, but not every change to
|
|
17
|
-
* the input element will affect the observable. Specifically, unless {onInput: true} is set, the
|
|
17
|
+
* the input element will affect the observable. Specifically, unless `{onInput: true}` is set, the
|
|
18
18
|
* visible content may differ from the observable until the element loses focus or Enter is hit.
|
|
19
19
|
*
|
|
20
20
|
* Example usage:
|
|
21
|
+
* ```
|
|
21
22
|
* input(obs, {}, {type: 'text', placeholder: 'Your name...'});
|
|
22
23
|
* input(obs, {isValid: isValidObs}, {type: 'email', placeholder: 'Your email...'});
|
|
23
24
|
* input(obs, {onInput: true}, {type: 'text'});
|
|
25
|
+
* ```
|
|
24
26
|
*/
|
|
25
27
|
export declare function input(obs: Observable<string>, options: IInputOptions, ...args: IDomArgs<HTMLInputElement>): HTMLInputElement;
|
|
@@ -13,26 +13,28 @@ const index_1 = require("../../index");
|
|
|
13
13
|
* number, tel.
|
|
14
14
|
*
|
|
15
15
|
* Note that every change to the observable will affect the input element, but not every change to
|
|
16
|
-
* the input element will affect the observable. Specifically, unless {onInput: true} is set, the
|
|
16
|
+
* the input element will affect the observable. Specifically, unless `{onInput: true}` is set, the
|
|
17
17
|
* visible content may differ from the observable until the element loses focus or Enter is hit.
|
|
18
18
|
*
|
|
19
19
|
* Example usage:
|
|
20
|
+
* ```
|
|
20
21
|
* input(obs, {}, {type: 'text', placeholder: 'Your name...'});
|
|
21
22
|
* input(obs, {isValid: isValidObs}, {type: 'email', placeholder: 'Your email...'});
|
|
22
23
|
* input(obs, {onInput: true}, {type: 'text'});
|
|
24
|
+
* ```
|
|
23
25
|
*/
|
|
24
26
|
function input(obs, options, ...args) {
|
|
25
27
|
const isValid = options.isValid;
|
|
26
28
|
function setValue(elem) {
|
|
27
|
-
index_1.bundleChanges(() => {
|
|
29
|
+
(0, index_1.bundleChanges)(() => {
|
|
28
30
|
obs.set(elem.value);
|
|
29
31
|
if (isValid) {
|
|
30
32
|
isValid.set(elem.validity.valid);
|
|
31
33
|
}
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
|
-
return index_1.dom('input', ...args, index_1.dom.prop('value', obs), (isValid ?
|
|
35
|
-
(elem) => index_1.dom.autoDisposeElem(elem, index_1.subscribe(obs, (use) => isValid.set(elem.checkValidity()))) :
|
|
36
|
+
return (0, index_1.dom)('input', ...args, index_1.dom.prop('value', obs), (isValid ?
|
|
37
|
+
(elem) => index_1.dom.autoDisposeElem(elem, (0, index_1.subscribe)(obs, (use) => isValid.set(elem.checkValidity()))) :
|
|
36
38
|
null), options.onInput ? index_1.dom.on('input', (e, elem) => setValue(elem)) : null, index_1.dom.on('change', (e, elem) => setValue(elem)), index_1.dom.onKeyPress({ Enter: (e, elem) => setValue(elem) }));
|
|
37
39
|
}
|
|
38
40
|
exports.input = input;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../../lib/widgets/input.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,uCAAgF;AAUhF
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../../lib/widgets/input.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,uCAAgF;AAUhF;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,KAAK,CACnB,GAAuB,EAAE,OAAsB,EAAE,GAAG,IAAgC;IAGpF,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAEhC,SAAS,QAAQ,CAAC,IAAsB;QACtC,IAAA,qBAAa,EAAC,GAAG,EAAE;YACjB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpB,IAAI,OAAO,EAAE;gBAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;aAAE;QACpD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAA,WAAG,EAAC,OAAO,EAAE,GAAG,IAAI,EACzB,WAAG,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,EACtB,CAAC,OAAO,CAAC,CAAC;QACR,CAAC,IAAI,EAAE,EAAE,CAAC,WAAG,CAAC,eAAe,CAAC,IAAI,EAChC,IAAA,iBAAS,EAAC,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,IAAI,CAAC,EACP,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,WAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EACrE,WAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAC7C,WAAG,CAAC,UAAU,CAAC,EAAC,KAAK,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAC,CAAC,CACrD,CAAC;AACJ,CAAC;AAvBD,sBAuBC"}
|
|
@@ -7,11 +7,11 @@ export interface IOptionFull<T> {
|
|
|
7
7
|
label: string;
|
|
8
8
|
disabled?: boolean;
|
|
9
9
|
}
|
|
10
|
-
export
|
|
10
|
+
export type IOption<T> = (T & string) | IOptionFull<T>;
|
|
11
11
|
/**
|
|
12
12
|
* Creates a select dropdown widget. The observable `obs` reflects the value of the selected
|
|
13
13
|
* option, and `optionArray` is an array (regular or observable) of option values and labels.
|
|
14
|
-
* These may be either strings, or {label, value, disabled} objects.
|
|
14
|
+
* These may be either strings, or `{label, value, disabled}` objects.
|
|
15
15
|
*
|
|
16
16
|
* The type of value may be any type at all; it is opaque to this widget.
|
|
17
17
|
*
|
|
@@ -19,6 +19,7 @@ export declare type IOption<T> = (T & string) | IOptionFull<T>;
|
|
|
19
19
|
* label that the select box will show, blank by default.
|
|
20
20
|
*
|
|
21
21
|
* Usage:
|
|
22
|
+
* ```
|
|
22
23
|
* const fruit = observable("apple");
|
|
23
24
|
* select(fruit, ["apple", "banana", "mango"]);
|
|
24
25
|
*
|
|
@@ -29,6 +30,7 @@ export declare type IOption<T> = (T & string) | IOptionFull<T>;
|
|
|
29
30
|
* {value: 21, label: "Eve"},
|
|
30
31
|
* ]);
|
|
31
32
|
* select(employee, employees, {defLabel: "Select employee:"});
|
|
33
|
+
* ```
|
|
32
34
|
*/
|
|
33
35
|
export declare function select<T>(obs: Observable<T>, optionArray: MaybeObsArray<IOption<T>>, options?: {
|
|
34
36
|
defLabel?: string;
|
|
@@ -15,7 +15,7 @@ function getOptionValue(option) {
|
|
|
15
15
|
/**
|
|
16
16
|
* Creates a select dropdown widget. The observable `obs` reflects the value of the selected
|
|
17
17
|
* option, and `optionArray` is an array (regular or observable) of option values and labels.
|
|
18
|
-
* These may be either strings, or {label, value, disabled} objects.
|
|
18
|
+
* These may be either strings, or `{label, value, disabled}` objects.
|
|
19
19
|
*
|
|
20
20
|
* The type of value may be any type at all; it is opaque to this widget.
|
|
21
21
|
*
|
|
@@ -23,6 +23,7 @@ function getOptionValue(option) {
|
|
|
23
23
|
* label that the select box will show, blank by default.
|
|
24
24
|
*
|
|
25
25
|
* Usage:
|
|
26
|
+
* ```
|
|
26
27
|
* const fruit = observable("apple");
|
|
27
28
|
* select(fruit, ["apple", "banana", "mango"]);
|
|
28
29
|
*
|
|
@@ -33,27 +34,28 @@ function getOptionValue(option) {
|
|
|
33
34
|
* {value: 21, label: "Eve"},
|
|
34
35
|
* ]);
|
|
35
36
|
* select(employee, employees, {defLabel: "Select employee:"});
|
|
37
|
+
* ```
|
|
36
38
|
*/
|
|
37
39
|
function select(obs, optionArray, options = {}) {
|
|
38
40
|
const { defLabel = "" } = options;
|
|
39
|
-
return index_1.dom('select',
|
|
41
|
+
return (0, index_1.dom)('select',
|
|
40
42
|
// Include a hidden option to represent a default value. This one gets shown when none of the
|
|
41
43
|
// options are selected. This is more consistent when showing the first valid option.
|
|
42
|
-
index_1.dom('option', index_1.dom.hide(true), defLabel),
|
|
44
|
+
(0, index_1.dom)('option', index_1.dom.hide(true), defLabel),
|
|
43
45
|
// Create all the option elements.
|
|
44
46
|
index_1.dom.forEach(optionArray, (option) => {
|
|
45
47
|
const obj = (typeof option === "string") ?
|
|
46
48
|
{ value: option, label: option } : option;
|
|
47
49
|
// Note we only set 'selected' when an <option> is created; we are not subscribing to obs.
|
|
48
50
|
// This is to reduce the amount of subscriptions, esp. when number of options is large.
|
|
49
|
-
return index_1.dom('option', {
|
|
51
|
+
return (0, index_1.dom)('option', {
|
|
50
52
|
disabled: obj.disabled,
|
|
51
53
|
selected: obj.value === obs.get(),
|
|
52
54
|
}, obj.label);
|
|
53
55
|
}),
|
|
54
56
|
// When obs changes, update select's value; we do it after <options> have been created.
|
|
55
57
|
// Note that autoDisposeElem ensures the subscription is disposed with the 'select' element.
|
|
56
|
-
(elem) => index_1.dom.autoDisposeElem(elem, index_1.subscribe(obs, (use, obsValue) => {
|
|
58
|
+
(elem) => index_1.dom.autoDisposeElem(elem, (0, index_1.subscribe)(obs, (use, obsValue) => {
|
|
57
59
|
const arr = unwrapMaybeObsArray(optionArray);
|
|
58
60
|
const index = arr.findIndex((item) => getOptionValue(item) === obsValue);
|
|
59
61
|
elem.selectedIndex = index + 1; // +1 for default option
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../../../lib/widgets/select.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,uCAAsE;AAWtE,SAAS,mBAAmB,CAAI,KAAuB;IACrD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AACpD,CAAC;AAED,SAAS,cAAc,CAAI,MAAkB;IAC3C,OAAO,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,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KAAK,KAAK,GAAG,CAAC,GAAG,EAAE;SAClC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;IAChB,CAAC,CAAC;IAEF,uFAAuF;IACvF,4FAA4F;IAC5F,CAAC,IAAI,EAAE,EAAE,CAAC,WAAG,CAAC,eAAe,CAAC,IAAI,EAAE,IAAA,iBAAS,EAAC,GAAG,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;QACnE,MAAM,GAAG,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;QAC7C,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,CAAC;QACzE,IAAI,CAAC,aAAa,GAAG,KAAK,GAAG,CAAC,CAAC,CAAI,wBAAwB;IAC7D,CAAC,CAAC,CAAC;IAEH,sEAAsE;IACtE,WAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC;QACjC,MAAM,IAAI,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAG,wBAAwB;QACpF,4FAA4F;QAC5F,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;SAC/B;IACH,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAtCD,wBAsCC"}
|
|
@@ -21,6 +21,9 @@ import { PriorityQueue } from './PriorityQueue';
|
|
|
21
21
|
* for subscriptions and computed observables.
|
|
22
22
|
*/
|
|
23
23
|
export class DepItem {
|
|
24
|
+
static isPrioritySmaller(a, b) {
|
|
25
|
+
return a._priority < b._priority || (a._priority === b._priority && a._creation < b._creation);
|
|
26
|
+
}
|
|
24
27
|
/**
|
|
25
28
|
* Callback should call depItem.useDep(dep) for each DepInput it depends on.
|
|
26
29
|
*/
|
|
@@ -32,9 +35,6 @@ export class DepItem {
|
|
|
32
35
|
this._callback = callback;
|
|
33
36
|
this._context = optContext;
|
|
34
37
|
}
|
|
35
|
-
static isPrioritySmaller(a, b) {
|
|
36
|
-
return a._priority < b._priority || (a._priority === b._priority && a._creation < b._creation);
|
|
37
|
-
}
|
|
38
38
|
/**
|
|
39
39
|
* Mark depItem as a dependency of this DepItem. The argument may be null to indicate a leaf (an
|
|
40
40
|
* item such as a plain observable, which does not itself depend on anything else).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_computed_queue.js","sourceRoot":"","sources":["../../../lib/_computed_queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C;;;GAGG;AACH,MAAM,OAAO,OAAO;
|
|
1
|
+
{"version":3,"file":"_computed_queue.js","sourceRoot":"","sources":["../../../lib/_computed_queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C;;;GAGG;AACH,MAAM,OAAO,OAAO;IACX,MAAM,CAAC,iBAAiB,CAAC,CAAU,EAAE,CAAU;QACpD,OAAO,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;IACjG,CAAC;IAUD;;OAEG;IACH,YAAY,QAAoB,EAAE,UAAmB;QAX7C,cAAS,GAAW,CAAC,CAAC;QACtB,cAAS,GAAY,KAAK,CAAC;QAInC,+DAA+D;QACvD,cAAS,GAAW,EAAE,gBAAgB,CAAC;QAM7C,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,QAAQ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AI;YACF,2EAA2E;YAC3E,GAAG;gBACD,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,EAAG,CAAC;gBAC1B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACjB,IAAI,CAAC,SAAS,EAAE,CAAC;aAClB,QAAQ,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE;SAC1B;gBAAS;YACR,2FAA2F;YAC3F,0DAA0D;YAC1D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;aACxB;YACD,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;YACjB,WAAW,EAAE,CAAC;SACf;KACF;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAI,IAAa;IAC5C,IAAI;QACF,WAAW,EAAE,CAAC;QACd,OAAO,IAAI,EAAE,CAAC;KACf;YAAS;QACR,WAAW,EAAE,CAAC;QACd,OAAO,EAAE,CAAC;KACX;AACH,CAAC"}
|
package/dist/esm/lib/binding.js
CHANGED
|
@@ -35,8 +35,8 @@ export function subscribeBindable(valueObs, callback) {
|
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Subscribes a callback to valueObs (which may be a value, observable, or function) using
|
|
39
|
-
*
|
|
38
|
+
* Subscribes a callback to `valueObs` (which may be a value, observable, or function) using
|
|
39
|
+
* `subscribeBindable()`, and ties the disposal of this subscription to the passed-in element.
|
|
40
40
|
*/
|
|
41
41
|
export function subscribeElem(elem, valueObs, callback) {
|
|
42
42
|
autoDisposeElem(elem, subscribeBindable(valueObs, callback));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../../../lib/binding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;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