Public constructor (which should never be called).
A TypeError upon construction.
Overridden function binding the FetchEffect to the polymorphic
this
of the StateWorker.
The explicit polymorphic this
parameter.
This FetchEffect bound to the StateWorker.
Implanted FetchEffect providing convenient access to the globalThis.fetch method within Store.Actions. Prefer the usage of this Effect over the globalThis.fetch method when StateWorker.dispatching Store.Actions.
A Promise of the fetched Response.
Invoke fetch within an Store.Action:
import { Stateful, Store } from '@sgrud/state';
@Stateful('io.github.sgrud.store.example', { response: undefined })
export class ExampleStore extends Store<ExampleStore> {
public readonly response?: unknown;
public async getResponse(url: string): Promise<Store.State<this>> {
const request = await sgrud.state.effects.fetch(url);
const response = await request.json();
if (!request.ok) {
throw response;
}
return { ...this, response };
}
}
Generated using TypeDoc
Built-in FetchEffect extending the abstract Effect base class. This FetchEffect is automatically StateWorker.implanted when the
@sgrud/state
module is imported and can therefore be always used in Store.Actions.Decorator
Implant
See
Effect