* Applies icon state to the icons on the block, based on the given state * object. * * @param block The block to set the icon state of. * @param state The state object to reference.
(block: Block, state: State)
| 624 | * @param state The state object to reference. |
| 625 | */ |
| 626 | function loadIcons(block: Block, state: State) { |
| 627 | if (!state['icons']) return; |
| 628 | |
| 629 | const iconTypes = Object.keys(state['icons']); |
| 630 | for (const iconType of iconTypes) { |
| 631 | const iconState = state['icons'][iconType]; |
| 632 | let icon = block.getIcon(iconType); |
| 633 | if (!icon) { |
| 634 | const constructor = registry.getClass( |
| 635 | registry.Type.ICON, |
| 636 | iconType, |
| 637 | false, |
| 638 | ); |
| 639 | if (!constructor) throw new UnregisteredIcon(iconType, block, state); |
| 640 | icon = new constructor(block); |
| 641 | block.addIcon(icon); |
| 642 | } |
| 643 | if (isSerializable(icon)) icon.loadState(iconState); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * Applies any field information available on the state object to the block. |
no test coverage detected