Actions
defineAction(name, options, handler) defines an action a block can bind to a button, menu item or
form. Its options are the same as on the Promise API: args,
input and state take Effect Schemas, and inputs, destructive, readOnly, idempotent,
agent, description, scopes, env and config are unchanged.
This action promotes a release when more members voted go than no-go, and fails with a tagged error
otherwise:
src/promote.ts
Deployments as a service it needs and Vetoed, plus whatever
deployments.promote can fail with, as its errors. A failed action leaves the block as it was and
shows the member an error. To show your own message instead, turn the failure into a result; see
Errors.
The handler returns the same results as on the Promise API:
state, notice, fieldErrors, openUrl, final, notify, revalidate and options.
Blocks and views
defineBlock(options) takes the block options with Effect Schemas for props
and state. .render(view) takes a view, which can be a generator, a function returning an
Effect or a Promise, or a function returning JSX:
src/launch.tsx
state decoded, so state.shippedAt is a Date. Services the view yields join the
services of its actions in the block’s type.
Components that return an Effect
A function component can return anEffect of JSX, so a part of a view can read a service on its
own:
"jsxImportSource": "@reintersect/sdk" in tsconfig.json already accepts these
components. The services a component reads aren’t tracked in any piece’s type, so make sure the app
provides them, for example because a view or action of the same app yields them too.
Inserting blocks
Block.insert(props, { state }) builds the block for a command or message action answer. Pass
state decoded; the SDK encodes it with the block’s schema:
blocks.update and decodes the state it reads back.
References
defineReference(kind, options) teaches Reintersect your links. resolve and search are Effect
handlers; the other options are the same as on the Promise API. This
example is the Effect template’s, and its Tasks service has find, search, add and
updateStatus:
src/taskReference.ts
params is typed from the pattern, so params.id is a string. The block preview’s state is
encoded with TaskBlock’s state schema before it’s sent. Services that resolve and search yield
become requirements of the reference.
If resolve fails, the SDK logs the failure and answers unavailable for that URL. Reintersect
keeps the link as it is and tries again later; the other URLs in the batch are unaffected.
Recipes
@reintersect/sdk/effect/recipes has every recipe as an Effect block, such as
checklist({ type: "launch-checklist" }). Add one to an Effect app the same way as your own blocks.