MCPcopy Create free account
hub / github.com/cryptii/cryptii / spliceBricks

Method spliceBricks

src/Pipe.js:337–456  ·  view source on GitHub ↗

* Removes and/or inserts bricks to the pipe at given index maintaining the * content buckets and triggering content propagation when needed. * @param {number} index Index at which bricks should be removed or inserted * @param {number} removeCount Amount of bricks to be removed * @param {

(index, removeCount, bricks = [])

Source from the content-addressed store, hash-verified

335 * @return {Brick[]} Array of bricks that have been removed
336 */
337 spliceBricks (index, removeCount, bricks = []) {
338 // Normalize index
339 index = index >= 0 ? index : Math.max(this._bricks.length + index + 1, 0)
340
341 // Reject all bucket listeners before changing bricks
342 this._bucketListeners.map(listeners => {
343 listeners.forEach(listener => listener.reject(
344 'Pipe bricks have been changed.'))
345 return []
346 })
347
348 // Instanciate serialized bricks
349 bricks = bricks.map(brick =>
350 !(brick instanceof Brick)
351 ? Brick.extract(brick, this.getBrickFactory())
352 : brick)
353
354 // Splice internal brick array
355 const removedBricks = this._bricks.splice.apply(this._bricks,
356 [index, removeCount].concat(bricks))
357
358 // Splice internal state array
359 this._brickState.splice.apply(this._brickState,
360 [index, removeCount].concat(bricks.map(() => ({
361 settingsVersion: 1,
362 busy: false
363 }))))
364
365 // Prepare added bricks, reset removed bricks
366 let bucketInsertCount = 0
367 let bucketRemoveCount = 0
368
369 bricks.forEach(brick => {
370 brick.setPipe(this)
371 this.hasView() && this.getView().addSubview(brick.getView())
372
373 if (brick instanceof Encoder) {
374 bucketInsertCount++
375 }
376
377 // Track event
378 EventManager.trigger('pipeAddBrick', { pipe: this, brick })
379 })
380
381 removedBricks.forEach(brick => {
382 this.hasView() && this.getView().removeSubview(brick.getView())
383 brick.setPipe(null)
384
385 if (brick instanceof Encoder) {
386 bucketRemoveCount++
387 }
388
389 // Track event
390 EventManager.trigger('pipeRemoveBrick', { pipe: this, brick })
391 })
392
393 // Update buckets if needed
394 if (bucketInsertCount > 0 || bucketRemoveCount > 0) {

Callers 11

addBrickMethod · 0.95
addBricksMethod · 0.95
duplicateBrickMethod · 0.95
moveBrickMethod · 0.95
removeBrickMethod · 0.95
removeBricksMethod · 0.95
replaceBrickMethod · 0.95
encoderDidReverseMethod · 0.95
viewAddButtonDidClickMethod · 0.95
viewBrickDidDropMethod · 0.95
Pipe.jsFile · 0.80

Calls 12

getBrickFactoryMethod · 0.95
_propagateContentMethod · 0.95
_triggerViewerViewMethod · 0.95
setPipeMethod · 0.80
hasViewMethod · 0.80
addSubviewMethod · 0.80
getViewMethod · 0.80
triggerMethod · 0.80
removeSubviewMethod · 0.80
emptyMethod · 0.80
extractMethod · 0.45
layoutMethod · 0.45

Tested by

no test coverage detected