Class: ReadOnlyChainMap
Defined in: src/chain_map.ts:32
A chain map groups multiple records together to create a single, read-only
view exposing a standard Record<string, unknown> interface.
Internally mappings are stored on a stack. Property resolution searches records on the stack from top to bottom, allowing properties from records at the top of the stack to mask properties from records at the bottom of the stack.
In the event that a property does not exist in the chain, property access
resolves to [Nothing] - the symbol used to indicate the absence of a
property rather than a property with a falsy or undefined value. This
avoids the need to call x in chainMap before chainMap[x] in some cases.
New records can be pushed onto and popped off the stack using [ChainPush]()
and [ChainPop](), respectively.
ReadOnlyChainMap is itself a Record<string, unknown>, so chain maps can
be arbitrarily nested.
ReadOnlyChainMap does not copy or freeze supplied records. Changes made to
records after they are added to the chain are immediately reflected in the
composite view.
Indexable
[
key:string]:unknown
Constructors
Constructor
new ReadOnlyChainMap(...
maps):ReadOnlyChainMap
Defined in: src/chain_map.ts:35
Parameters
maps
...Readonly<Record<string, unknown>>[]
Returns
ReadOnlyChainMap
Methods
[ChainKeys]()
[ChainKeys]():
string[]
Defined in: src/chain_map.ts:152
Compiles an array containing all unique keys across the stack hierarchy.
Returns
string[]
[ChainPop]()
[ChainPop]():
Record<string,unknown> |undefined
Defined in: src/chain_map.ts:145
Pop and return the record off the top of the stack.
Returns
Record<string, unknown> | undefined
[ChainPush]()
[ChainPush](
map):void
Defined in: src/chain_map.ts:138
Push map onto the top of the stack.
Parameters
map
Readonly<Record<string, unknown>>
Returns
void
[ChainSize]()
[ChainSize]():
number
Defined in: src/chain_map.ts:170
Returns the total number of discrete map layers currently on the stack.
Returns
number
[iterator]()
[iterator]():
Generator<[string,unknown],void,unknown>
Defined in: src/chain_map.ts:177
Iterates over the composite map view, yielding [key, value] pairs.
Returns
Generator<[string, unknown], void, unknown>