| 12 | * It will not do anything if instantiated directly. |
| 13 | */ |
| 14 | export class ComponentContainer extends Component { |
| 15 | private _detachCallback: ComponentCallback; |
| 16 | |
| 17 | constructor() { |
| 18 | super(); |
| 19 | this._detachCallback = (component: Component) => this.remove(component); |
| 20 | } |
| 21 | |
| 22 | public anchor(selection: d3.Selection<HTMLElement, any, any, any>) { |
| 23 | selection = coerceExternalD3(selection); |
| 24 | super.anchor(selection); |
| 25 | this._forEach((c) => c.anchor(this.element())); |
| 26 | return this; |
| 27 | } |
| 28 | |
| 29 | public render() { |
| 30 | this._forEach((c) => c.render()); |
| 31 | return this; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Checks whether the specified Component is in the ComponentContainer. |
| 36 | */ |
| 37 | public has(component: Component): boolean { |
| 38 | throw new Error("has() is not implemented on ComponentContainer"); |
| 39 | } |
| 40 | |
| 41 | protected _adoptAndAnchor(component: Component) { |
| 42 | component.parent(this); |
| 43 | component.onDetach(this._detachCallback); |
| 44 | if (this._isAnchored) { |
| 45 | component.anchor(this.element()); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Removes the specified Component from the ComponentContainer. |
| 51 | */ |
| 52 | public remove(component: Component) { |
| 53 | if (this.has(component)) { |
| 54 | component.offDetach(this._detachCallback); |
| 55 | this._remove(component); |
| 56 | component.detach(); |
| 57 | this.redraw(); |
| 58 | } |
| 59 | return this; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Carry out the actual removal of a Component. |
| 64 | * Implementation dependent on the type of container. |
| 65 | * |
| 66 | * @return {boolean} true if the Component was successfully removed, false otherwise. |
| 67 | */ |
| 68 | protected _remove(component: Component) { |
| 69 | return false; |
| 70 | } |
| 71 |
nothing calls this directly
no outgoing calls
no test coverage detected