* Unbind a binding from the context. No parent contexts will be checked. * * @remarks * If you need to unbind a binding owned by a parent context, use the code * below: * * ```ts * const ownerCtx = ctx.getOwnerContext(key); * return ownerCtx != null && ownerCtx.unbind(key);
(key: BindingAddress)
| 386 | * @returns true if the binding key is found and removed from this context |
| 387 | */ |
| 388 | unbind(key: BindingAddress): boolean { |
| 389 | this.debug('Unbind %s', key); |
| 390 | key = BindingKey.validate(key); |
| 391 | const binding = this.registry.get(key); |
| 392 | // If not found, return `false` |
| 393 | if (binding == null) return false; |
| 394 | if (binding?.isLocked) |
| 395 | throw new Error(`Cannot unbind key "${key}" of a locked binding`); |
| 396 | this.registry.delete(key); |
| 397 | this.emitEvent('unbind', {binding, context: this, type: 'unbind'}); |
| 398 | return true; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Add a context event observer to the context |
no test coverage detected