@loopback/context 1.25.1 → 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/CHANGELOG.md +48 -0
- package/dist/binding-filter.d.ts +19 -1
- package/dist/binding-filter.js +40 -7
- package/dist/binding-filter.js.map +1 -1
- package/dist/binding.d.ts +33 -1
- package/dist/binding.js +14 -1
- package/dist/binding.js.map +1 -1
- package/dist/context-event.d.ts +23 -0
- package/dist/context-event.js +7 -0
- package/dist/context-event.js.map +1 -0
- package/dist/context-observer.d.ts +1 -36
- package/dist/context-subscription.d.ts +147 -0
- package/dist/context-subscription.js +336 -0
- package/dist/context-subscription.js.map +1 -0
- package/dist/context-tag-indexer.d.ts +42 -0
- package/dist/context-tag-indexer.js +134 -0
- package/dist/context-tag-indexer.js.map +1 -0
- package/dist/context-view.d.ts +2 -1
- package/dist/context-view.js.map +1 -1
- package/dist/context.d.ts +29 -65
- package/dist/context.js +50 -245
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/inject.d.ts +1 -1
- package/dist/interceptor.js +4 -4
- package/dist/interceptor.js.map +1 -1
- package/dist/invocation.d.ts +0 -1
- package/dist/invocation.js +1 -5
- package/dist/invocation.js.map +1 -1
- package/dist/value-promise.d.ts +1 -3
- package/package.json +7 -7
- package/src/binding-filter.ts +61 -9
- package/src/binding.ts +43 -1
- package/src/context-event.ts +30 -0
- package/src/context-observer.ts +1 -38
- package/src/context-subscription.ts +403 -0
- package/src/context-tag-indexer.ts +149 -0
- package/src/context-view.ts +2 -5
- package/src/context.ts +71 -286
- package/src/index.ts +2 -0
- package/src/interceptor.ts +7 -6
- package/src/invocation.ts +1 -3
- package/src/value-promise.ts +1 -1
package/dist/interceptor.js
CHANGED
|
@@ -11,7 +11,6 @@ const metadata_1 = require("@loopback/metadata");
|
|
|
11
11
|
const assert_1 = __importDefault(require("assert"));
|
|
12
12
|
const debug_1 = __importDefault(require("debug"));
|
|
13
13
|
const binding_decorator_1 = require("./binding-decorator");
|
|
14
|
-
const binding_filter_1 = require("./binding-filter");
|
|
15
14
|
const binding_sorter_1 = require("./binding-sorter");
|
|
16
15
|
const interceptor_chain_1 = require("./interceptor-chain");
|
|
17
16
|
const invocation_1 = require("./invocation");
|
|
@@ -27,9 +26,10 @@ class InterceptedInvocationContext extends invocation_1.InvocationContext {
|
|
|
27
26
|
* ContextTags.GLOBAL_INTERCEPTOR)
|
|
28
27
|
*/
|
|
29
28
|
getGlobalInterceptorBindingKeys() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
let bindings = this.findByTag(keys_1.ContextTags.GLOBAL_INTERCEPTOR);
|
|
30
|
+
bindings = bindings.filter(binding =>
|
|
31
|
+
// Only include interceptors that match the source type of the invocation
|
|
32
|
+
this.applicableTo(binding));
|
|
33
33
|
this.sortGlobalInterceptorBindings(bindings);
|
|
34
34
|
const keys = bindings.map(b => b.key);
|
|
35
35
|
debug('Global interceptor binding keys:', keys);
|
package/dist/interceptor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interceptor.js","sourceRoot":"","sources":["../src/interceptor.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,iDAO4B;AAC5B,oDAA4B;AAC5B,kDAAiC;AAEjC,2DAAyC;
|
|
1
|
+
{"version":3,"file":"interceptor.js","sourceRoot":"","sources":["../src/interceptor.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,iDAO4B;AAC5B,oDAA4B;AAC5B,kDAAiC;AAEjC,2DAAyC;AAEzC,qDAAqD;AAErD,2DAI6B;AAC7B,6CAKsB;AACtB,iCAIgB;AAChB,mDAA+D;AAC/D,MAAM,KAAK,GAAG,eAAY,CAAC,8BAA8B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AClB,IAAoB,EACpB,UAA6B,EAAE;IAE/B,oEAAoE;IACpE,iCAAiC;IACjC,gBAAM,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,iCAAiC,CAAC,CAAC;IACrE,MAAM,aAAa,GAAG,IAAI,4BAA4B,CACpD,OAAO,EACP,MAAM,EACN,UAAU,EACV,IAAI,EACJ,OAAO,CAAC,MAAM,CACf,CAAC;IAEF,aAAa,CAAC,kBAAkB,EAAE,CAAC;IACnC,OAAO,8BAAc,CACnB,GAAG,EAAE;QACH,MAAM,YAAY,GAAG,aAAa,CAAC,gBAAgB,EAAE,CAAC;QACtD,MAAM,mBAAmB,GAAG,GAAG,EAAE,CAC/B,aAAa,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAC5C,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACvC,OAAO,sCAAkB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IACzD,CAAC,EACD,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,CAC5B,CAAC;AACJ,CAAC;AA7BD,oEA6BC"}
|
package/dist/invocation.d.ts
CHANGED
|
@@ -27,7 +27,6 @@ export interface InvocationSource<T = unknown> {
|
|
|
27
27
|
* other dependencies.
|
|
28
28
|
*/
|
|
29
29
|
export declare class InvocationContext extends Context {
|
|
30
|
-
readonly parent: Context;
|
|
31
30
|
readonly target: object;
|
|
32
31
|
readonly methodName: string;
|
|
33
32
|
readonly args: InvocationArgs;
|
package/dist/invocation.js
CHANGED
|
@@ -30,12 +30,8 @@ class InvocationContext extends context_1.Context {
|
|
|
30
30
|
* @param methodName - Method name
|
|
31
31
|
* @param args - An array of arguments
|
|
32
32
|
*/
|
|
33
|
-
constructor(
|
|
34
|
-
// Make `parent` public so that the interceptor can add bindings to
|
|
35
|
-
// the request context, for example, tracing id
|
|
36
|
-
parent, target, methodName, args, source) {
|
|
33
|
+
constructor(parent, target, methodName, args, source) {
|
|
37
34
|
super(parent);
|
|
38
|
-
this.parent = parent;
|
|
39
35
|
this.target = target;
|
|
40
36
|
this.methodName = methodName;
|
|
41
37
|
this.args = args;
|
package/dist/invocation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invocation.js","sourceRoot":"","sources":["../src/invocation.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,iDAAoD;AACpD,oDAA4B;AAC5B,kDAAiC;AACjC,uCAAkC;AAClC,+CAA2D;AAC3D,yCAAoD;AACpD,mDAAwE;AAExE,MAAM,KAAK,GAAG,eAAY,CAAC,6BAA6B,CAAC,CAAC;AAC1D,MAAM,aAAa,GAAG,2BAAgB,CAAC,aAAa,CAAC;AA4BrD;;;;GAIG;AACH,MAAa,iBAAkB,SAAQ,iBAAO;IAC5C;;;;;;;OAOG;IACH
|
|
1
|
+
{"version":3,"file":"invocation.js","sourceRoot":"","sources":["../src/invocation.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,iDAAoD;AACpD,oDAA4B;AAC5B,kDAAiC;AACjC,uCAAkC;AAClC,+CAA2D;AAC3D,yCAAoD;AACpD,mDAAwE;AAExE,MAAM,KAAK,GAAG,eAAY,CAAC,6BAA6B,CAAC,CAAC;AAC1D,MAAM,aAAa,GAAG,2BAAgB,CAAC,aAAa,CAAC;AA4BrD;;;;GAIG;AACH,MAAa,iBAAkB,SAAQ,iBAAO;IAC5C;;;;;;;OAOG;IACH,YACE,MAAe,EACC,MAAc,EACd,UAAkB,EAClB,IAAoB,EACpB,MAAyB;QAEzC,KAAK,CAAC,MAAM,CAAC,CAAC;QALE,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAQ;QAClB,SAAI,GAAJ,IAAI,CAAgB;QACpB,WAAM,GAAN,MAAM,CAAmB;IAG3C,CAAC;IAED;;OAEG;IACH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M,YAAY,CAC7B,CAAC;IACF,OAAO,uCAAuB,CAAC,aAAa,EAAE,IAAI,CAAC,EAAE;QACnD,wBAAwB;QACxB,IAAI,KAAK,CAAC,OAAO,EAAE;YACjB,KAAK,CAAC,4BAA4B,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;SACvD;QACD,OAAO,kBAAkB,CAAC,GAAG,EAAE,iBAAiB,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,GAAY,EAAE,WAAW;AACzB,MAAc,EACd,UAAkB,EAClB,IAAoB;IAEpB,MAAM,iBAAiB,GAAG,MAAkC,CAAC;IAC7D,wBAAwB;IACxB,IAAI,KAAK,CAAC,OAAO,EAAE;QACjB,KAAK,CAAC,oBAAoB,EAAE,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC;KACtE;IACD,2BAA2B;IAC3B,MAAM,MAAM,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACtD,wBAAwB;IACxB,IAAI,KAAK,CAAC,OAAO,EAAE;QACjB,KAAK,CAAC,oBAAoB,EAAE,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;KACxE;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/value-promise.d.ts
CHANGED
|
@@ -17,9 +17,7 @@ export declare type BoundValue = any;
|
|
|
17
17
|
* provided by JavaScript runtime.
|
|
18
18
|
*/
|
|
19
19
|
export declare type ValueOrPromise<T> = T | PromiseLike<T>;
|
|
20
|
-
export declare type MapObject<T> =
|
|
21
|
-
[name: string]: T;
|
|
22
|
-
};
|
|
20
|
+
export declare type MapObject<T> = Record<string, T>;
|
|
23
21
|
/**
|
|
24
22
|
* Check whether a value is a Promise-like instance.
|
|
25
23
|
* Recognizes both native promises and third-party promise libraries.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/context",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "LoopBack's container for Inversion of Control",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.9"
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"copyright.owner": "IBM Corp.",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@loopback/metadata": "^1.
|
|
21
|
+
"@loopback/metadata": "^1.4.0",
|
|
22
22
|
"debug": "^4.1.1",
|
|
23
23
|
"p-event": "^4.1.0",
|
|
24
|
-
"uuid": "^3.
|
|
24
|
+
"uuid": "^3.4.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@loopback/build": "^3.0
|
|
28
|
-
"@loopback/eslint-config": "^5.0.
|
|
29
|
-
"@loopback/testlab": "^1.10.
|
|
27
|
+
"@loopback/build": "^3.1.0",
|
|
28
|
+
"@loopback/eslint-config": "^5.0.2",
|
|
29
|
+
"@loopback/testlab": "^1.10.2",
|
|
30
30
|
"@types/bluebird": "^3.5.29",
|
|
31
31
|
"@types/debug": "^4.1.5",
|
|
32
32
|
"@types/node": "^10.17.13",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"url": "https://github.com/strongloop/loopback-next.git",
|
|
56
56
|
"directory": "packages/context"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "d08f135a0d1040edc61497739a8d86a866e4e29a"
|
|
59
59
|
}
|
package/src/binding-filter.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import {Binding, BindingTag} from './binding';
|
|
7
7
|
import {BindingAddress} from './binding-key';
|
|
8
|
+
import {MapObject} from './value-promise';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* A function that filters bindings. It returns `true` to select a given
|
|
@@ -59,27 +60,78 @@ export function isBindingAddress(
|
|
|
59
60
|
return typeof bindingSelector !== 'function';
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Binding filter function that holds a binding tag pattern. `Context.find()`
|
|
65
|
+
* uses the `bindingTagPattern` to optimize the matching of bindings by tag to
|
|
66
|
+
* avoid expensive check for all bindings.
|
|
67
|
+
*/
|
|
68
|
+
export interface BindingTagFilter extends BindingFilter<unknown> {
|
|
69
|
+
/**
|
|
70
|
+
* A special property on the filter function to provide access to the binding
|
|
71
|
+
* tag pattern which can be utilized to optimize the matching of bindings by
|
|
72
|
+
* tag in a context.
|
|
73
|
+
*/
|
|
74
|
+
bindingTagPattern: BindingTag | RegExp;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Type guard for BindingTagFilter
|
|
79
|
+
* @param filter - A BindingFilter function
|
|
80
|
+
*/
|
|
81
|
+
export function isBindingTagFilter(
|
|
82
|
+
filter?: BindingFilter,
|
|
83
|
+
): filter is BindingTagFilter {
|
|
84
|
+
if (filter == null || !('bindingTagPattern' in filter)) return false;
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
+
const tagPattern = (filter as any).bindingTagPattern;
|
|
87
|
+
return (
|
|
88
|
+
tagPattern instanceof RegExp ||
|
|
89
|
+
typeof tagPattern === 'string' ||
|
|
90
|
+
typeof tagPattern === 'object'
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
62
94
|
/**
|
|
63
95
|
* Create a binding filter for the tag pattern
|
|
64
96
|
* @param tagPattern - Binding tag name, regexp, or object
|
|
65
97
|
*/
|
|
66
|
-
export function filterByTag(tagPattern: BindingTag | RegExp):
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
98
|
+
export function filterByTag(tagPattern: BindingTag | RegExp): BindingTagFilter {
|
|
99
|
+
let filter: BindingFilter;
|
|
100
|
+
let regex: RegExp | undefined = undefined;
|
|
101
|
+
if (tagPattern instanceof RegExp) {
|
|
102
|
+
// RegExp for tag names
|
|
103
|
+
regex = tagPattern;
|
|
104
|
+
}
|
|
105
|
+
if (
|
|
106
|
+
typeof tagPattern === 'string' &&
|
|
107
|
+
(tagPattern.includes('*') || tagPattern.includes('?'))
|
|
108
|
+
) {
|
|
109
|
+
// Wildcard tag name
|
|
110
|
+
regex = wildcardToRegExp(tagPattern);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (regex != null) {
|
|
114
|
+
// RegExp or wildcard match
|
|
115
|
+
filter = b => b.tagNames.some(t => regex!.test(t));
|
|
116
|
+
} else if (typeof tagPattern === 'string') {
|
|
117
|
+
// Plain tag string match
|
|
118
|
+
filter = b => b.tagNames.includes(tagPattern);
|
|
73
119
|
} else {
|
|
74
|
-
|
|
120
|
+
// Match tag name/value pairs
|
|
121
|
+
const tagMap = tagPattern as MapObject<unknown>;
|
|
122
|
+
filter = b => {
|
|
75
123
|
for (const t in tagPattern) {
|
|
76
124
|
// One tag name/value does not match
|
|
77
|
-
if (b.tagMap[t] !==
|
|
125
|
+
if (b.tagMap[t] !== tagMap[t]) return false;
|
|
78
126
|
}
|
|
79
127
|
// All tag name/value pairs match
|
|
80
128
|
return true;
|
|
81
129
|
};
|
|
82
130
|
}
|
|
131
|
+
// Set up binding tag for the filter
|
|
132
|
+
const tagFilter = filter as BindingTagFilter;
|
|
133
|
+
tagFilter.bindingTagPattern = regex ?? tagPattern;
|
|
134
|
+
return tagFilter;
|
|
83
135
|
}
|
|
84
136
|
|
|
85
137
|
/**
|
package/src/binding.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
6
|
import debugFactory from 'debug';
|
|
7
|
+
import {EventEmitter} from 'events';
|
|
7
8
|
import {BindingAddress, BindingKey} from './binding-key';
|
|
8
9
|
import {Context} from './context';
|
|
9
10
|
import {createProxyWithInterceptors} from './interception-proxy';
|
|
@@ -139,6 +140,34 @@ export type BindingTag = TagMap | string;
|
|
|
139
140
|
*/
|
|
140
141
|
export type BindingTemplate<T = unknown> = (binding: Binding<T>) => void;
|
|
141
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Information for a binding event
|
|
145
|
+
*/
|
|
146
|
+
export type BindingEvent = {
|
|
147
|
+
/**
|
|
148
|
+
* Event type
|
|
149
|
+
*/
|
|
150
|
+
type: string;
|
|
151
|
+
/**
|
|
152
|
+
* Source binding that emits the event
|
|
153
|
+
*/
|
|
154
|
+
binding: Readonly<Binding<unknown>>;
|
|
155
|
+
/**
|
|
156
|
+
* Operation that triggers the event
|
|
157
|
+
*/
|
|
158
|
+
operation: string;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Event listeners for binding events
|
|
163
|
+
*/
|
|
164
|
+
export type BindingEventListener = (
|
|
165
|
+
/**
|
|
166
|
+
* Binding event
|
|
167
|
+
*/
|
|
168
|
+
event: BindingEvent,
|
|
169
|
+
) => void;
|
|
170
|
+
|
|
142
171
|
type ValueGetter<T> = (
|
|
143
172
|
ctx: Context,
|
|
144
173
|
options: ResolutionOptions,
|
|
@@ -148,7 +177,7 @@ type ValueGetter<T> = (
|
|
|
148
177
|
* Binding represents an entry in the `Context`. Each binding has a key and a
|
|
149
178
|
* corresponding value getter.
|
|
150
179
|
*/
|
|
151
|
-
export class Binding<T = BoundValue> {
|
|
180
|
+
export class Binding<T = BoundValue> extends EventEmitter {
|
|
152
181
|
/**
|
|
153
182
|
* Key of the binding
|
|
154
183
|
*/
|
|
@@ -199,6 +228,7 @@ export class Binding<T = BoundValue> {
|
|
|
199
228
|
}
|
|
200
229
|
|
|
201
230
|
constructor(key: BindingAddress<T>, public isLocked: boolean = false) {
|
|
231
|
+
super();
|
|
202
232
|
BindingKey.validate(key);
|
|
203
233
|
this.key = key.toString();
|
|
204
234
|
}
|
|
@@ -324,6 +354,15 @@ export class Binding<T = BoundValue> {
|
|
|
324
354
|
return this;
|
|
325
355
|
}
|
|
326
356
|
|
|
357
|
+
/**
|
|
358
|
+
* Emit a `changed` event
|
|
359
|
+
* @param operation - Operation that makes changes
|
|
360
|
+
*/
|
|
361
|
+
private emitChangedEvent(operation: string) {
|
|
362
|
+
const event: BindingEvent = {binding: this, operation, type: 'changed'};
|
|
363
|
+
this.emit('changed', event);
|
|
364
|
+
}
|
|
365
|
+
|
|
327
366
|
/**
|
|
328
367
|
* Tag the binding with names or name/value objects. A tag has a name and
|
|
329
368
|
* an optional value. If not supplied, the tag name is used as the value.
|
|
@@ -362,6 +401,7 @@ export class Binding<T = BoundValue> {
|
|
|
362
401
|
Object.assign(this.tagMap, t);
|
|
363
402
|
}
|
|
364
403
|
}
|
|
404
|
+
this.emitChangedEvent('tag');
|
|
365
405
|
return this;
|
|
366
406
|
}
|
|
367
407
|
|
|
@@ -379,6 +419,7 @@ export class Binding<T = BoundValue> {
|
|
|
379
419
|
inScope(scope: BindingScope): this {
|
|
380
420
|
if (this._scope !== scope) this._clearCache();
|
|
381
421
|
this._scope = scope;
|
|
422
|
+
this.emitChangedEvent('scope');
|
|
382
423
|
return this;
|
|
383
424
|
}
|
|
384
425
|
|
|
@@ -409,6 +450,7 @@ export class Binding<T = BoundValue> {
|
|
|
409
450
|
}
|
|
410
451
|
return getValue(ctx, options);
|
|
411
452
|
};
|
|
453
|
+
this.emitChangedEvent('value');
|
|
412
454
|
}
|
|
413
455
|
|
|
414
456
|
/**
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/context
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import {Binding} from './binding';
|
|
7
|
+
import {Context} from './context';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Events emitted by a context
|
|
11
|
+
*/
|
|
12
|
+
export type ContextEvent = {
|
|
13
|
+
/**
|
|
14
|
+
* Source context that emits the event
|
|
15
|
+
*/
|
|
16
|
+
context: Context;
|
|
17
|
+
/**
|
|
18
|
+
* Binding that is being added/removed/updated
|
|
19
|
+
*/
|
|
20
|
+
binding: Readonly<Binding<unknown>>;
|
|
21
|
+
/**
|
|
22
|
+
* Event type
|
|
23
|
+
*/
|
|
24
|
+
type: string; // 'bind' or 'unbind'
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Synchronous listener for context events
|
|
29
|
+
*/
|
|
30
|
+
export type ContextEventListener = (event: ContextEvent) => void;
|
package/src/context-observer.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
import {Binding} from './binding';
|
|
7
7
|
import {BindingFilter} from './binding-filter';
|
|
8
|
-
import {ValueOrPromise} from './value-promise';
|
|
9
8
|
import {Context} from './context';
|
|
9
|
+
import {ValueOrPromise} from './value-promise';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Context event types. We support `bind` and `unbind` for now but
|
|
@@ -48,40 +48,3 @@ export interface ContextObserver {
|
|
|
48
48
|
* Context event observer type - An instance of `ContextObserver` or a function
|
|
49
49
|
*/
|
|
50
50
|
export type ContextEventObserver = ContextObserver | ContextObserverFn;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Subscription of context events. It's modeled after
|
|
54
|
-
* https://github.com/tc39/proposal-observable.
|
|
55
|
-
*/
|
|
56
|
-
export interface Subscription {
|
|
57
|
-
/**
|
|
58
|
-
* unsubscribe
|
|
59
|
-
*/
|
|
60
|
-
unsubscribe(): void;
|
|
61
|
-
/**
|
|
62
|
-
* Is the subscription closed?
|
|
63
|
-
*/
|
|
64
|
-
closed: boolean;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Event data for observer notifications
|
|
69
|
-
*/
|
|
70
|
-
export type Notification = {
|
|
71
|
-
/**
|
|
72
|
-
* Context event type - bind/unbind
|
|
73
|
-
*/
|
|
74
|
-
eventType: ContextEventType;
|
|
75
|
-
/**
|
|
76
|
-
* Binding added/removed
|
|
77
|
-
*/
|
|
78
|
-
binding: Readonly<Binding<unknown>>;
|
|
79
|
-
/**
|
|
80
|
-
* Owner context for the binding
|
|
81
|
-
*/
|
|
82
|
-
context: Context;
|
|
83
|
-
/**
|
|
84
|
-
* A snapshot of observers when the original event is emitted
|
|
85
|
-
*/
|
|
86
|
-
observers: Set<ContextEventObserver>;
|
|
87
|
-
};
|