Class: Manager
Singleton which manages state of all known paths. It provides two functionalities: 1) Executes Operations
to either cache the resulting State
in conjuction with its _query_
or invalidate its dependent paths, and 2) Accepts subscriptions to cached State
via queries and notifies relevant subscribers whenever cached State
change.
Hierarchy
- Manager
Index
Constructors
Properties
Methods
Constructors
constructor
+ new Manager(maxSize
: number): Manager
Defined in lib/control/Manager.ts:71
Parameters:
Name | Type | Default |
---|---|---|
maxSize |
number | null |
Returns: Manager
Properties
Private
active
• active: Map‹string, Promise‹State›› = new Map()
Defined in lib/control/Manager.ts:62
Stores queries which are actively being calculated, along with a promise resolving to their eventual state.
Private
globals
• globals: Cache = new LocalCache()
Defined in lib/control/Manager.ts:59
An object that implements the Cache
interface, which will be used to store cached State
and dependency graphs. By defualt, this is an instance of LocalCache
, but when operating in a clustered environment, this should overriden with a global cache.
Private
listeners
• listeners: Set‹Function› = new Set()
Defined in lib/control/Manager.ts:71
A set containing functions (path, internal) => {...}
which will be invoked when any path is invalidated, with the invalidated path string and a boolean denoting whether the invalidating initiated by a caller other than the Manager
.
Protected
maxSize
• maxSize: number = 25000
Defined in lib/control/Manager.ts:56
The maximum number of queries that can be cached before an eviction
occurs.
Private
operations
• operations: Map‹string, Operation› = new Map()
Defined in lib/control/Manager.ts:65
Maps queries to cacheable operations
that will be invoked to recalculate their {@linkcode Manager.states|state}.
Private
subscriptions
• subscriptions: Relation‹Function, string› = new Relation()
Defined in lib/control/Manager.ts:68
Maps subscribers (represented by callback functions) to queries and vice versa. Whenever a query is recalculated
, its associated subscribers will be invoked with the resulting state.
Static
Private
instance
▪ instance: Manager
Defined in lib/control/Manager.ts:53
The instance of Manager (or derived class) currently accessible via the Manager singleton, using {@linkcode Mangager.access}.
Methods
Private
cache
▸ cache(operation
: Operation): Promise‹State›
Defined in lib/control/Manager.ts:81
Executes the given operation
and stores it as well as the resulting state
in association with the operation's query
.
Parameters:
Name | Type |
---|---|
operation |
Operation |
Returns: Promise‹State›
Private
evict
▸ evict(): Promise‹boolean›
Defined in lib/control/Manager.ts:119
Removes the oldest cached query with no associated subscribers.
Returns: Promise‹boolean›
execute
▸ execute(operation
: Operation): Promise‹State›
Defined in lib/control/Manager.ts:173
Safely invokes an operation
, caching the resulting state
if applicable or otherwise invalidating dependent paths.
Parameters:
Name | Type |
---|---|
operation |
Operation |
Returns: Promise‹State›
invalidate
▸ invalidate(paths
: string | Array‹string›, override
: boolean): Promise‹void›
Defined in lib/control/Manager.ts:148
Invalidates a path, possibly alerting listeners
and causing all associated queries to be recalculated.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
paths |
string | Array‹string› | - | - |
override |
boolean | false | If true , signifies that listeners should not be notified of the invalidated paths. |
Returns: Promise‹void›
listen
▸ listen(callback
: Function): void
Defined in lib/control/Manager.ts:194
Registers a function callback
to be invoked whenever a path is invalidated.
Parameters:
Name | Type | Description |
---|---|---|
callback |
Function | A function (path, internal) => {} . |
Returns: void
subscribe
▸ subscribe(client
: Function, query
: string): boolean
Defined in lib/control/Manager.ts:206
Registers a subscriber
to be invoked whenever the state of query
changes.
Parameters:
Name | Type | Default |
---|---|---|
client |
Function | - |
query |
string | null |
Returns: boolean
unlisten
▸ unlisten(callback
: Function): void
Defined in lib/control/Manager.ts:199
Unregisters a listener function callback
.
Parameters:
Name | Type |
---|---|
callback |
Function |
Returns: void
Private
unset
▸ unset(query
: string): Promise‹void›
Defined in lib/control/Manager.ts:134
Removes a query from the cache along with all of its associations.
Parameters:
Name | Type | Description |
---|---|---|
query |
string | A query string. |
Returns: Promise‹void›
unsubscribe
▸ unsubscribe(client
: Function, query
: string): void
Defined in lib/control/Manager.ts:215
Unregisters a subscriber
from the given query
, or from all subscribed queries if no query
is provided.
Parameters:
Name | Type | Default |
---|---|---|
client |
Function | - |
query |
string | null |
Returns: void
Static
access
▸ access(): Manager
Defined in lib/control/Manager.ts:220
Returns the Manager singleton instance. If the singleton instance has not been manually defined using Manager.initialize
, a default instance of Manager
will be created.
Returns: Manager
Static
initialize
▸ initialize(instance
: Manager): void
Defined in lib/control/Manager.ts:231
Sets the Manager singleton instance that will be accessible
throughout the application instance.
Parameters:
Name | Type | Description |
---|---|---|
instance |
Manager |
Returns: void