* Update Block data. * * Currently we don't have an 'update' method in the Tools API, so we just create a new block with the same id and type * Should not trigger 'block-removed' or 'block-added' events. * * If neither data nor tunes is provided, return the provided block instead.
(block: Block, data?: Partial<BlockToolData>, tunes?: {[name: string]: BlockTuneData})
| 346 | * @param tunes - (optional) tune data |
| 347 | */ |
| 348 | public async update(block: Block, data?: Partial<BlockToolData>, tunes?: {[name: string]: BlockTuneData}): Promise<Block> { |
| 349 | if (!data && !tunes) { |
| 350 | return block; |
| 351 | } |
| 352 | |
| 353 | const existingData = await block.data; |
| 354 | |
| 355 | const newBlock = this.composeBlock({ |
| 356 | id: block.id, |
| 357 | tool: block.name, |
| 358 | data: Object.assign({}, existingData, data ?? {}), |
| 359 | tunes: tunes ?? block.tunes, |
| 360 | }); |
| 361 | |
| 362 | const blockIndex = this.getBlockIndex(block); |
| 363 | |
| 364 | this._blocks.replace(blockIndex, newBlock); |
| 365 | |
| 366 | this.blockDidMutated(BlockChangedMutationType, newBlock, { |
| 367 | index: blockIndex, |
| 368 | }); |
| 369 | |
| 370 | return newBlock; |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * Replace passed Block with the new one with specified Tool and data |
nothing calls this directly
no test coverage detected