* 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)
| 241 | * @returns The context value or throws error if there is no context value for this key |
| 242 | */ |
| 243 | public getContext(key: string): any { |
| 244 | const value = this._context?.[key]; |
| 245 | |
| 246 | if (value !== undefined) { return value; } |
| 247 | |
| 248 | if (value === undefined && !this.scope?.node) { |
| 249 | throw new Error(`No context value present for ${key} key`); |
| 250 | } |
| 251 | |
| 252 | return this.scope && this.scope.node.getContext(key); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Retrieves the all context of a node from tree context. |