-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
582 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright IBM Corp. 2018. All Rights Reserved. | ||
// Node module: @loopback/context | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {Binding} from './binding'; | ||
import {BindingFilter} from './binding-filter'; | ||
import {ValueOrPromise} from './value-promise'; | ||
import {Context} from './context'; | ||
|
||
/** | ||
* Context event types. We support `bind` and `unbind` for now but | ||
* keep it open for new types | ||
*/ | ||
export type ContextEventType = 'bind' | 'unbind' | string; | ||
|
||
/** | ||
* Observers of context bind/unbind events | ||
*/ | ||
export interface ContextObserver { | ||
/** | ||
* An optional filter function to match bindings. If not present, the listener | ||
* will be notified of all binding events. | ||
*/ | ||
filter?: BindingFilter; | ||
|
||
/** | ||
* Listen on `bind`, `unbind`, or other events | ||
* @param eventType Context event type | ||
* @param binding The binding as event source | ||
*/ | ||
observe( | ||
eventType: ContextEventType, | ||
binding: Readonly<Binding<unknown>>, | ||
context: Context, | ||
): ValueOrPromise<void>; | ||
} | ||
|
||
/** | ||
* Subscription of context events. It's modeled after | ||
* https://github.com/tc39/proposal-observable. | ||
*/ | ||
export interface Subscription { | ||
/** | ||
* unsubscribe | ||
*/ | ||
unsubscribe(): void; | ||
/** | ||
* Is the subscription closed? | ||
*/ | ||
closed: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.