* Removes bricks from the pipe. * Convenience method calling Pipe.spliceBricks internally. * @param {Brick[]|number[]} bricksOrIndexes Array of bricks or indexes * to be removed * @throws {Error} If one of the bricks is not part of the pipe. * @return {Pipe} Fluent interface
(bricksOrIndexes)
| 287 | * @return {Pipe} Fluent interface |
| 288 | */ |
| 289 | removeBricks (bricksOrIndexes) { |
| 290 | bricksOrIndexes |
| 291 | // Map brick instances to indexes |
| 292 | .map(brickOrIndex => { |
| 293 | let index = brickOrIndex |
| 294 | if (brickOrIndex instanceof Brick) { |
| 295 | index = this._bricks.indexOf(brickOrIndex) |
| 296 | if (index === -1) { |
| 297 | throw new Error( |
| 298 | 'Brick is not part of the pipe and thus can\'t be removed.') |
| 299 | } |
| 300 | } |
| 301 | return index |
| 302 | }) |
| 303 | // Sort indexes in descending order |
| 304 | .sort((a, b) => b - a) |
| 305 | // Remove each |
| 306 | .forEach(index => this.spliceBricks(index, 1)) |
| 307 | return this |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Replaces a single brick. |
nothing calls this directly
no test coverage detected