* Retrieves a value from tree context if present. Otherwise, would throw an error. * * Context is usually initialized at the root, but can be overridden at any point in the tree. * * @param key The context key * @returns The context value or throws error if there is no context value f
(key: string)
| 267 | * @returns The context value or throws error if there is no context value for this key |
| 268 | */ |
| 269 | public getContext(key: string): any { |
| 270 | const value = this._context?.[key]; |
| 271 | |
| 272 | if (value !== undefined) { return value; } |
| 273 | |
| 274 | if (value === undefined && !this.scope?.node) { |
| 275 | throw new Error(`No context value present for ${key} key`); |
| 276 | } |
| 277 | |
| 278 | return this.scope && this.scope.node.getContext(key); |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Retrieves the all context of a node from tree context. |