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


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


Constructor Modifiers Description
(constructor)(context, filter, comparator)   Create a context view


Property Modifiers Type Description
_cachedBindings   Readonly<Binding<T>>[] | undefined An array of cached bindings that matches the binding filter
_cachedValues   Map<Readonly<Binding<T>>, T> | undefined A map of cached values by binding
bindings   Readonly<Binding<T>>[] Get the list of matched bindings. If they are not cached, it tries to find them from the context.
comparator   BindingComparator | undefined  
context   Context  
filter   BindingFilter  


Method Modifiers Description
asGetter(session)   As a Getter function
close()   Stop listening events from the context
findBindings()   Find matching bindings and refresh the cache
observe(event, binding, context)   Listen on bind or unbind and invalidate the cache
open()   Start listening events from the context
refresh()   Refresh the view by invalidating its cache
resolve(session)   Resolve values for the matching bindings
singleValue(session)   Get the single value
values(session)   Get the list of resolved values. If they are not cached, it tries to find and resolve them.