Resources
Resources are the main way to connect Starbeam to external input data.
If you're used to using effects to connect external inputs in other frameworks, resources serve a similar purpose. The primary difference is that resources expose reactive data, just like FormulaFn.
The author of a resource sets up an imperative subscription, defines the cleanup logic for the subscription, and returns a function that computes the current value of the resource.
As the resource modifies its internal cells, the value of the resource is always up to date with the result of the computation.
File "/opt/build/repo/src/api/core/" does not existResources are defined in terms of Starbeam APIs, and then wired into applications through renderers.
For example, you could use the stopwatch in the above example in React by using the useResource hook from @starbeam/react.
File "/opt/build/repo/src/api/core/" does not existResource
TThe type of value that the resource represents.
Constructor Function
function Resource(blueprint, description?): ResourceBlueprint;The Resource function returns a ResourceBlueprint, which is an unlinked resource. You call create() on the blueprint with an owner to instantiate the resource and link its lifetime to the specified owner object.
blueprint(create: ResourceBuilder) => () => TA function that sets up a resource and returns a function that computes the current value of the resource.
description?stringA description of the resource.
optionalreturnsResourceBlueprint
Properties
current
readonly current: T;The current value of the resource.
ResourceBlueprint
bolt Methods
create
create(options): Resource;options{ owner: object }the owner to link the resource to.
returnsResourceA resource that computes the given value.
ResourceBuilder
bolt Methods
on.setup
on.setup(setup, description?): Unsubscribe;setup() => () => voidA reactive setup function.
description?stringA description of the setup logic.
optionalreturnsUnsubscribeAn unsubscribe function that can be used to stop the setup function from being called again.