@loopback/context 1.23.5 → 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 +81 -0
- package/dist/binding-config.js +1 -1
- package/dist/binding-config.js.map +1 -1
- 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-inspector.js +12 -11
- package/dist/binding-inspector.js.map +1 -1
- package/dist/binding-sorter.js +2 -2
- package/dist/binding-sorter.js.map +1 -1
- package/dist/binding.d.ts +42 -4
- package/dist/binding.js +40 -10
- 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 +5 -2
- package/dist/context-view.js.map +1 -1
- package/dist/context.d.ts +35 -66
- package/dist/context.js +78 -250
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/inject-config.js +3 -3
- package/dist/inject-config.js.map +1 -1
- package/dist/inject.d.ts +2 -2
- package/dist/inject.js +18 -11
- package/dist/inject.js.map +1 -1
- package/dist/interception-proxy.d.ts +15 -3
- package/dist/interception-proxy.js +20 -4
- package/dist/interception-proxy.js.map +1 -1
- package/dist/interceptor-chain.js +5 -2
- package/dist/interceptor-chain.js.map +1 -1
- package/dist/interceptor.d.ts +6 -0
- package/dist/interceptor.js +38 -12
- package/dist/interceptor.js.map +1 -1
- package/dist/invocation.d.ts +20 -2
- package/dist/invocation.js +14 -12
- package/dist/invocation.js.map +1 -1
- package/dist/keys.d.ts +6 -0
- package/dist/keys.js +6 -0
- package/dist/keys.js.map +1 -1
- package/dist/resolution-session.d.ts +1 -0
- package/dist/resolution-session.js +13 -6
- package/dist/resolution-session.js.map +1 -1
- package/dist/resolver.js +13 -8
- package/dist/resolver.js.map +1 -1
- package/dist/value-promise.d.ts +1 -3
- package/package.json +9 -9
- package/src/binding-config.ts +1 -1
- package/src/binding-filter.ts +61 -9
- package/src/binding-inspector.ts +6 -8
- package/src/binding-sorter.ts +2 -2
- package/src/binding.ts +73 -9
- 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 +3 -6
- package/src/context.ts +94 -293
- package/src/index.ts +5 -3
- package/src/inject-config.ts +3 -3
- package/src/inject.ts +19 -10
- package/src/interception-proxy.ts +25 -3
- package/src/interceptor-chain.ts +1 -1
- package/src/interceptor.ts +34 -8
- package/src/invocation.ts +26 -7
- package/src/keys.ts +7 -0
- package/src/resolution-session.ts +9 -5
- package/src/resolver.ts +5 -5
- package/src/value-promise.ts +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/context
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const binding_filter_1 = require("./binding-filter");
|
|
8
|
+
/**
|
|
9
|
+
* Indexer for context bindings by tag
|
|
10
|
+
*/
|
|
11
|
+
class ContextTagIndexer {
|
|
12
|
+
constructor(context) {
|
|
13
|
+
this.context = context;
|
|
14
|
+
/**
|
|
15
|
+
* Index for bindings by tag names
|
|
16
|
+
*/
|
|
17
|
+
this.bindingsIndexedByTag = new Map();
|
|
18
|
+
this.setupTagIndexForBindings();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Set up context/binding listeners and refresh index for bindings by tag
|
|
22
|
+
*/
|
|
23
|
+
setupTagIndexForBindings() {
|
|
24
|
+
this.bindingEventListener = ({ binding, operation }) => {
|
|
25
|
+
if (operation === 'tag') {
|
|
26
|
+
this.updateTagIndexForBinding(binding);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
this.tagIndexListener = event => {
|
|
30
|
+
const { binding, type } = event;
|
|
31
|
+
if (event.context !== this.context)
|
|
32
|
+
return;
|
|
33
|
+
if (type === 'bind') {
|
|
34
|
+
this.updateTagIndexForBinding(binding);
|
|
35
|
+
binding.on('changed', this.bindingEventListener);
|
|
36
|
+
}
|
|
37
|
+
else if (type === 'unbind') {
|
|
38
|
+
this.removeTagIndexForBinding(binding);
|
|
39
|
+
binding.removeListener('changed', this.bindingEventListener);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
this.context.on('bind', this.tagIndexListener);
|
|
43
|
+
this.context.on('unbind', this.tagIndexListener);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Remove tag index for the given binding
|
|
47
|
+
* @param binding - Binding object
|
|
48
|
+
*/
|
|
49
|
+
removeTagIndexForBinding(binding) {
|
|
50
|
+
for (const [, bindings] of this.bindingsIndexedByTag) {
|
|
51
|
+
bindings.delete(binding);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Update tag index for the given binding
|
|
56
|
+
* @param binding - Binding object
|
|
57
|
+
*/
|
|
58
|
+
updateTagIndexForBinding(binding) {
|
|
59
|
+
this.removeTagIndexForBinding(binding);
|
|
60
|
+
for (const tag of binding.tagNames) {
|
|
61
|
+
let bindings = this.bindingsIndexedByTag.get(tag);
|
|
62
|
+
if (bindings == null) {
|
|
63
|
+
bindings = new Set();
|
|
64
|
+
this.bindingsIndexedByTag.set(tag, bindings);
|
|
65
|
+
}
|
|
66
|
+
bindings.add(binding);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Find bindings by tag leveraging indexes
|
|
71
|
+
* @param tag - Tag name pattern or name/value pairs
|
|
72
|
+
*/
|
|
73
|
+
findByTagIndex(tag) {
|
|
74
|
+
let tagNames;
|
|
75
|
+
// A flag to control if a union of matched bindings should be created
|
|
76
|
+
let union = false;
|
|
77
|
+
if (tag instanceof RegExp) {
|
|
78
|
+
// For wildcard/regexp, a union of matched bindings is desired
|
|
79
|
+
union = true;
|
|
80
|
+
// Find all matching tag names
|
|
81
|
+
tagNames = [];
|
|
82
|
+
for (const t of this.bindingsIndexedByTag.keys()) {
|
|
83
|
+
if (tag.test(t)) {
|
|
84
|
+
tagNames.push(t);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (typeof tag === 'string') {
|
|
89
|
+
tagNames = [tag];
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
tagNames = Object.keys(tag);
|
|
93
|
+
}
|
|
94
|
+
let filter;
|
|
95
|
+
let bindings;
|
|
96
|
+
for (const t of tagNames) {
|
|
97
|
+
const bindingsByTag = this.bindingsIndexedByTag.get(t);
|
|
98
|
+
if (bindingsByTag == null)
|
|
99
|
+
break; // One of the tags is not found
|
|
100
|
+
filter = (filter !== null && filter !== void 0 ? filter : binding_filter_1.filterByTag(tag));
|
|
101
|
+
const matched = new Set(Array.from(bindingsByTag).filter(filter));
|
|
102
|
+
if (!union && matched.size === 0)
|
|
103
|
+
break; // One of the tag name/value is not found
|
|
104
|
+
if (bindings == null) {
|
|
105
|
+
// First set of bindings matching the tag
|
|
106
|
+
bindings = matched;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
if (union) {
|
|
110
|
+
matched.forEach(b => { var _a; return (_a = bindings) === null || _a === void 0 ? void 0 : _a.add(b); });
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// Now need to find intersected bindings against visited tags
|
|
114
|
+
const intersection = new Set();
|
|
115
|
+
bindings.forEach(b => {
|
|
116
|
+
if (matched.has(b)) {
|
|
117
|
+
intersection.add(b);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
bindings = intersection;
|
|
121
|
+
}
|
|
122
|
+
if (!union && bindings.size === 0)
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return bindings == null ? [] : Array.from(bindings);
|
|
127
|
+
}
|
|
128
|
+
close() {
|
|
129
|
+
this.context.removeListener('bind', this.tagIndexListener);
|
|
130
|
+
this.context.removeListener('unbind', this.tagIndexListener);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.ContextTagIndexer = ContextTagIndexer;
|
|
134
|
+
//# sourceMappingURL=context-tag-indexer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-tag-indexer.js","sourceRoot":"","sources":["../src/context-tag-indexer.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;AAGhE,qDAA4D;AAK5D;;GAEG;AACH,MAAa,iBAAiB;IAmB5B,YAA+B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;QAlB/C;;WAEG;QACM,yBAAoB,GAGzB,IAAI,GAAG,EAAE,CAAC;QAaZ,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAClC,CAAC;IAED;;OAEG;IACK,wBAAwB;QAC9B,IAAI,CAAC,oBAAoB,GAAG,CAAC,EAAC,OAAO,EAAE,SAAS,EAAC,EAAE,EAAE;YACnD,IAAI,SAAS,KAAK,KAAK,EAAE;gBACvB,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;aACxC;QACH,CAAC,CAAC;QACF,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,EAAE;YAC9B,MAAM,EAAC,OAAO,EAAE,IAAI,EAAC,GAAG,KAAK,CAAC;YAC9B,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO;gBA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AO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,wBAAC,QAAQ,0CAAE,GAAG,CAAC,CAAC,IAAC,CAAC,CAAC;iBACxC;qBAAM;oBACL,6DAA6D;oBAC7D,MAAM,YAAY,GAAG,IAAI,GAAG,EAAgC,CAAC;oBAC7D,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;wBACnB,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;4BAClB,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;yBACrB;oBACH,CAAC,CAAC,CAAC;oBACH,QAAQ,GAAG,YAAY,CAAC;iBACzB;gBACD,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAC;oBAAE,MAAM;aAC1C;SACF;QACD,OAAO,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC3D,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC/D,CAAC;CACF;AAtID,8CAsIC"}
|
package/dist/context-view.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { Binding } from './binding';
|
|
|
4
4
|
import { BindingFilter } from './binding-filter';
|
|
5
5
|
import { BindingComparator } from './binding-sorter';
|
|
6
6
|
import { Context } from './context';
|
|
7
|
-
import { ContextEventType, ContextObserver
|
|
7
|
+
import { ContextEventType, ContextObserver } from './context-observer';
|
|
8
|
+
import { Subscription } from './context-subscription';
|
|
8
9
|
import { Getter } from './inject';
|
|
9
10
|
import { ResolutionSession } from './resolution-session';
|
|
10
11
|
import { ValueOrPromise } from './value-promise';
|
package/dist/context-view.js
CHANGED
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
// Node module: @loopback/context
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const
|
|
10
|
+
const debug_1 = __importDefault(require("debug"));
|
|
8
11
|
const events_1 = require("events");
|
|
9
12
|
const util_1 = require("util");
|
|
10
13
|
const resolution_session_1 = require("./resolution-session");
|
|
11
14
|
const value_promise_1 = require("./value-promise");
|
|
12
|
-
const debug =
|
|
15
|
+
const debug = debug_1.default('loopback:context:view');
|
|
13
16
|
const nextTick = util_1.promisify(process.nextTick);
|
|
14
17
|
/**
|
|
15
18
|
* `ContextView` provides a view for a given context chain to maintain a live
|
package/dist/context-view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-view.js","sourceRoot":"","sources":["../src/context-view.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE
|
|
1
|
+
{"version":3,"file":"context-view.js","sourceRoot":"","sources":["../src/context-view.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,kDAAiC;AACjC,mCAAoC;AACpC,+BAA+B;AAQ/B,6DAAuD;AACvD,mDAA2E;AAC3E,MAAM,KAAK,GAAG,eAAY,CAAC,uBAAuB,CAAC,CAAC;AACpD,MAAM,QAAQ,GAAG,gBAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE7C;;;;;;;;;;;;;GAaG;AACH,MAAa,WAAyB,SAAQ,qBAAY;IAMxD,YACqB,OAAgB,EACnB,MAAqB,EACrB,UAA8B;QAE9C,KAAK,EAAE,CAAC;QAJW,YAAO,GAA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AO,CAAC,CAAC;AAChC,CAAC;AAhBD,4CAgBC"}
|
package/dist/context.d.ts
CHANGED
|
@@ -5,7 +5,10 @@ import { ConfigurationResolver } from './binding-config';
|
|
|
5
5
|
import { BindingFilter } from './binding-filter';
|
|
6
6
|
import { BindingAddress } from './binding-key';
|
|
7
7
|
import { BindingComparator } from './binding-sorter';
|
|
8
|
-
import {
|
|
8
|
+
import { ContextEvent } from './context-event';
|
|
9
|
+
import { ContextEventObserver, ContextObserver } from './context-observer';
|
|
10
|
+
import { ContextSubscriptionManager, Subscription } from './context-subscription';
|
|
11
|
+
import { ContextTagIndexer } from './context-tag-indexer';
|
|
9
12
|
import { ContextView } from './context-view';
|
|
10
13
|
import { ResolutionOptions, ResolutionOptionsOrSession, ResolutionSession } from './resolution-session';
|
|
11
14
|
import { BoundValue, ValueOrPromise } from './value-promise';
|
|
@@ -22,30 +25,21 @@ export declare class Context extends EventEmitter {
|
|
|
22
25
|
*/
|
|
23
26
|
protected readonly registry: Map<string, Binding>;
|
|
24
27
|
/**
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
protected _parent?: Context;
|
|
28
|
-
protected configResolver: ConfigurationResolver;
|
|
29
|
-
/**
|
|
30
|
-
* Event listeners for parent context keyed by event names. It keeps track
|
|
31
|
-
* of listeners from this context against its parent so that we can remove
|
|
32
|
-
* these listeners when this context is closed.
|
|
28
|
+
* Indexer for bindings by tag
|
|
33
29
|
*/
|
|
34
|
-
protected
|
|
30
|
+
protected readonly tagIndexer: ContextTagIndexer;
|
|
35
31
|
/**
|
|
36
|
-
*
|
|
37
|
-
* first observer is added.
|
|
32
|
+
* Manager for observer subscriptions
|
|
38
33
|
*/
|
|
39
|
-
|
|
34
|
+
readonly subscriptionManager: ContextSubscriptionManager;
|
|
40
35
|
/**
|
|
41
|
-
*
|
|
42
|
-
* processed by observers.
|
|
36
|
+
* Parent context
|
|
43
37
|
*/
|
|
44
|
-
|
|
38
|
+
protected _parent?: Context;
|
|
45
39
|
/**
|
|
46
|
-
*
|
|
40
|
+
* Configuration resolver
|
|
47
41
|
*/
|
|
48
|
-
|
|
42
|
+
protected configResolver: ConfigurationResolver;
|
|
49
43
|
/**
|
|
50
44
|
* Create a new context.
|
|
51
45
|
*
|
|
@@ -69,6 +63,11 @@ export declare class Context extends EventEmitter {
|
|
|
69
63
|
* generated as the name
|
|
70
64
|
*/
|
|
71
65
|
constructor(_parent?: Context | string, name?: string);
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
* Getter for ContextSubscriptionManager
|
|
69
|
+
*/
|
|
70
|
+
get parent(): Context | undefined;
|
|
72
71
|
/**
|
|
73
72
|
* Wrap the debug statement so that it always print out the context name
|
|
74
73
|
* as the prefix
|
|
@@ -76,44 +75,16 @@ export declare class Context extends EventEmitter {
|
|
|
76
75
|
*/
|
|
77
76
|
private _debug;
|
|
78
77
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
private setupEventHandlersIfNeeded;
|
|
84
|
-
/**
|
|
85
|
-
* Add an event listener to its parent context so that this context will
|
|
86
|
-
* be notified of parent events, such as `bind` or `unbind`.
|
|
87
|
-
* @param event - Event name
|
|
88
|
-
*/
|
|
89
|
-
private addParentEventListener;
|
|
90
|
-
/**
|
|
91
|
-
* Handle errors caught during the notification of observers
|
|
92
|
-
* @param err - Error
|
|
78
|
+
* A strongly-typed method to emit context events
|
|
79
|
+
* @param type Event type
|
|
80
|
+
* @param event Context event
|
|
93
81
|
*/
|
|
94
|
-
|
|
82
|
+
emitEvent<T extends ContextEvent>(type: string, event: T): void;
|
|
95
83
|
/**
|
|
96
|
-
*
|
|
84
|
+
* Emit an `error` event
|
|
85
|
+
* @param err Error
|
|
97
86
|
*/
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Process notification events as they arrive on the queue
|
|
101
|
-
*/
|
|
102
|
-
private processNotifications;
|
|
103
|
-
/**
|
|
104
|
-
* Listen on given event types and emit `notification` event. This method
|
|
105
|
-
* merge multiple event types into one for notification.
|
|
106
|
-
* @param eventTypes - Context event types
|
|
107
|
-
*/
|
|
108
|
-
private setupNotification;
|
|
109
|
-
/**
|
|
110
|
-
* Wait until observers are notified for all of currently pending notification
|
|
111
|
-
* events.
|
|
112
|
-
*
|
|
113
|
-
* This method is for test only to perform assertions after observers are
|
|
114
|
-
* notified for relevant events.
|
|
115
|
-
*/
|
|
116
|
-
protected waitUntilPendingNotificationsDone(timeout?: number): Promise<void>;
|
|
87
|
+
emitError(err: unknown): void;
|
|
117
88
|
/**
|
|
118
89
|
* Create a binding with the given key in the context. If a locked binding
|
|
119
90
|
* already exists with the same key, an error will be thrown.
|
|
@@ -220,18 +191,6 @@ export declare class Context extends EventEmitter {
|
|
|
220
191
|
* @param comparator - A function to sort matched bindings
|
|
221
192
|
*/
|
|
222
193
|
createView<T = unknown>(filter: BindingFilter, comparator?: BindingComparator): ContextView<T>;
|
|
223
|
-
/**
|
|
224
|
-
* Publish an event to the registered observers. Please note the
|
|
225
|
-
* notification is queued and performed asynchronously so that we allow fluent
|
|
226
|
-
* APIs such as `ctx.bind('key').to(...).tag(...);` and give observers the
|
|
227
|
-
* fully populated binding.
|
|
228
|
-
*
|
|
229
|
-
* @param eventType - Event names: `bind` or `unbind`
|
|
230
|
-
* @param binding - Binding bound or unbound
|
|
231
|
-
* @param context - Owner context
|
|
232
|
-
* @param observers - Current set of context observers
|
|
233
|
-
*/
|
|
234
|
-
protected notifyObservers(eventType: ContextEventType, binding: Readonly<Binding<unknown>>, context: Context, observers?: Set<ContextEventObserver> | undefined): Promise<void>;
|
|
235
194
|
/**
|
|
236
195
|
* Check if a binding exists with the given key in the local context without
|
|
237
196
|
* delegating to the parent context
|
|
@@ -278,6 +237,11 @@ export declare class Context extends EventEmitter {
|
|
|
278
237
|
* `{name: 'my-controller'}`
|
|
279
238
|
*/
|
|
280
239
|
findByTag<ValueType = BoundValue>(tagFilter: BindingTag | RegExp): Readonly<Binding<ValueType>>[];
|
|
240
|
+
/**
|
|
241
|
+
* Find bindings by tag leveraging indexes
|
|
242
|
+
* @param tag - Tag name pattern or name/value pairs
|
|
243
|
+
*/
|
|
244
|
+
protected _findByTagIndex<ValueType = BoundValue>(tag: BindingTag | RegExp): Readonly<Binding<ValueType>>[];
|
|
281
245
|
protected _mergeWithParent<ValueType>(childList: Readonly<Binding<ValueType>>[], parentList?: Readonly<Binding<ValueType>>[]): Readonly<Binding<ValueType>>[];
|
|
282
246
|
/**
|
|
283
247
|
* Get the value bound to the given key, throw an error when no value is
|
|
@@ -430,7 +394,12 @@ export declare class Context extends EventEmitter {
|
|
|
430
394
|
/**
|
|
431
395
|
* Create a plain JSON object for the context
|
|
432
396
|
*/
|
|
433
|
-
toJSON():
|
|
397
|
+
toJSON(): object;
|
|
398
|
+
/**
|
|
399
|
+
* Inspect the context and dump out a JSON object representing the context
|
|
400
|
+
* hierarchy
|
|
401
|
+
*/
|
|
402
|
+
inspect(): object;
|
|
434
403
|
}
|
|
435
404
|
/**
|
|
436
405
|
* Policy to control if a binding should be created for the context
|