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: - ‘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 

Constructors

Constructor Modifiers Description
(constructor)(context, filter, comparator)   Constructs a new instance of the ContextView class

Properties

Property Modifiers Type Description
_cachedBindings   Readonly<Binding<T>>[] | undefined  
_cachedValues   T[] | undefined  
comparator   BindingComparator | undefined  
context   Context  
filter   BindingFilter  

Methods

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)   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.