* This can be used to set contextual values. * Context must be set before any children are added, since children may consult context info during construction. * If the key already exists, it will be overridden. * @param key The context key * @param value The context value
(key: string, value: any)
| 248 | * @param value The context value |
| 249 | */ |
| 250 | public setContext(key: string, value: any) { |
| 251 | if (this.children.length > 0) { |
| 252 | const names = this.children.map(c => c.node.id); |
| 253 | throw new Error('Cannot set context after children have been added: ' + names.join(',')); |
| 254 | } |
| 255 | if (!this._context) { |
| 256 | this._context = {}; |
| 257 | } |
| 258 | this._context[key] = value; |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Retrieves a value from tree context if present. Otherwise, would throw an error. |
no outgoing calls