Page Contents

Home > @loopback/context > ContextView

ContextView class

ContextView provides a view for a given context chain to maintain a live list of matching bindings and their resolved values within the context hierarchy.

This class is the key utility to implement dynamic extensions for extension points. For example, the RestServer can react to controller bindings even they are added/removed/updated after the application starts.

ContextView is an event emitter that emits the following events: - ‘bind’: when a binding is added to the view - ‘unbind’: when a binding is removed from the view - ‘close’: when the view is closed (stopped observing context events) - ‘refresh’: when the view is refreshed as bindings are added/removed - ‘resolve’: when the cached values are resolved and updated

Signature:

export declare class ContextView<T = unknown> extends EventEmitter implements ContextObserver 

Extends: EventEmitter

Implements: ContextObserver

Constructors

Constructor Modifiers Description
[(constructor)(context, filter, comparator, resolutionOptions)](/doc/en/lb4/apidocs.context.contextview._constructor_.html) Create a context view

Properties

Property Modifiers Type Description
[\_cachedBindings](/doc/en/lb4/apidocs.context.contextview._cachedbindings.html) `protected` Readonly<[Binding](/doc/en/lb4/apidocs.context.binding.html)<T>>\[\] \| undefined An array of cached bindings that matches the binding filter
[\_cachedValues](/doc/en/lb4/apidocs.context.contextview._cachedvalues.html) `protected` Map<Readonly<[Binding](/doc/en/lb4/apidocs.context.binding.html)<T>>, T> \| undefined A map of cached values by binding
[bindings](/doc/en/lb4/apidocs.context.contextview.bindings.html) `readonly` Readonly<[Binding](/doc/en/lb4/apidocs.context.binding.html)<T>>\[\] Get the list of matched bindings. If they are not cached, it tries to find them from the context.
[comparator?](/doc/en/lb4/apidocs.context.contextview.comparator.html) `readonly` [BindingComparator](/doc/en/lb4/apidocs.context.bindingcomparator.html) \| undefined _(Optional)_
[context](/doc/en/lb4/apidocs.context.contextview.context.html) `readonly` [Context](/doc/en/lb4/apidocs.context.context.html)
[filter](/doc/en/lb4/apidocs.context.contextview.filter.html) `readonly` [BindingFilter](/doc/en/lb4/apidocs.context.bindingfilter.html)

Methods

Method Modifiers Description
[asGetter(session)](/doc/en/lb4/apidocs.context.contextview.asgetter.html) As a `Getter` function
[close()](/doc/en/lb4/apidocs.context.contextview.close.html) Stop listening events from the context
[findBindings()](/doc/en/lb4/apidocs.context.contextview.findbindings.html) `protected` Find matching bindings and refresh the cache
[observe(event, binding, context)](/doc/en/lb4/apidocs.context.contextview.observe.html) Listen on `bind` or `unbind` and invalidate the cache
[on(eventName, listener)](/doc/en/lb4/apidocs.context.contextview.on.html) The "bind" event is emitted when a new binding is added to the view.
[on(eventName, listener)](/doc/en/lb4/apidocs.context.contextview.on_1.html) The "unbind" event is emitted a new binding is removed from the view.
[on(eventName, listener)](/doc/en/lb4/apidocs.context.contextview.on_2.html) The "refresh" event is emitted when the view is refreshed as bindings are added/removed.
[on(eventName, listener)](/doc/en/lb4/apidocs.context.contextview.on_3.html) The "resolve" event is emitted when the cached values are resolved and updated.
[on(eventName, listener)](/doc/en/lb4/apidocs.context.contextview.on_4.html) The "close" event is emitted when the view is closed (stopped observing context events)
[on(event, listener)](/doc/en/lb4/apidocs.context.contextview.on_5.html)
[once(eventName, listener)](/doc/en/lb4/apidocs.context.contextview.once.html) The "bind" event is emitted when a new binding is added to the view.
[once(eventName, listener)](/doc/en/lb4/apidocs.context.contextview.once_1.html) The "unbind" event is emitted a new binding is removed from the view.
[once(eventName, listener)](/doc/en/lb4/apidocs.context.contextview.once_2.html) The "refresh" event is emitted when the view is refreshed as bindings are added/removed.
[once(eventName, listener)](/doc/en/lb4/apidocs.context.contextview.once_3.html) The "resolve" event is emitted when the cached values are resolved and updated.
[once(eventName, listener)](/doc/en/lb4/apidocs.context.contextview.once_4.html) The "close" event is emitted when the view is closed (stopped observing context events)
[once(event, listener)](/doc/en/lb4/apidocs.context.contextview.once_5.html)
[open()](/doc/en/lb4/apidocs.context.contextview.open.html) Start listening events from the context
[refresh()](/doc/en/lb4/apidocs.context.contextview.refresh.html) Refresh the view by invalidating its cache
[resolve(session)](/doc/en/lb4/apidocs.context.contextview.resolve.html) Resolve values for the matching bindings
[singleValue(session)](/doc/en/lb4/apidocs.context.contextview.singlevalue.html) Get the single value
[values(session)](/doc/en/lb4/apidocs.context.contextview.values.html) Get the list of resolved values. If they are not cached, it tries to find and resolve them.