State
In this example, we will show you how to use CreativeEditor SDK's CreativeEngine to retrieve's a block's state and to manually set a block in a pending state, an error state or back to a ready state. Blocks can perform operations that take some time or that can end in bad results. When that happens, blocks put themselves in a pending state or an error state and visual feedback is shown pertaining to the state. When an external operation is done to blocks, for example with a plugin, you may want to manually set the block's state to pending (if that external operation takes time) or to error (if that operation resulted in an error).
The possible states of a block are:
When calling getState
, the returned state reflects the combined state of a block, the block's fill, the block's shape and the block's effects.
If any of these blocks is in an Error
state, the returned state will reflect that error.
If none of these blocks is in error state but any is in Pending
state, the returned state will reflect the aggregate progress of the block's progress.
If none of the blocks are in error state or pending state, the returned state is Ready
.
Setup#
This example uses the headless CreativeEngine. See the Setup article for a detailed guide.
To get started right away, you can also access the block
API within a running CE.SDK instance via cesdk.engine.block
.
Check out the APIs Overview to see that illustrated in more detail.
getState(id: DesignBlockId): BlockState
Returns the block's state. If this block is in error state or this block has a Shape
block, Fill
block or Effect
block(s), that is in error state, the returned state will be Error
. Else, if this block is in pending state or this block has a Shape
block, Fill
block or Effect
block(s), that is in pending state, the returned state will be Pending
. Else, the returned state will be Ready
.
id
: The block to query.- Returns The block's state.
setState(id: DesignBlockId, state: BlockState): void
Set the state of a block.
id
: The block whose state should be set.state
: The new state to set.
onStateChanged: (ids: DesignBlockId[], callback: (ids: DesignBlockId[]) => void) => (() => void)
Subscribe to changes to the state of a block. Like getState
, the state of a block is determined by the state of itself and its Shape
, Fill
and Effect
block(s).
blocks
: A list of blocks to filter events by. If the list is empty, events for every block are sent.callback
: The event callback.- Returns Subscription A handle to the subscription. Use it to unsubscribe when done.