Type Aliases
Context
Context
<TData, TError, TFailure>: { data
: TData | null; edits
: Partial<TData> | null; errors
: TError[]; failure
: TFailure | null }Type Parameters
TData extends Data = Data
TError = unknown
TFailure = unknown
Type declaration
data: TData | null
edits: Partial<TData> | null
errors: TError[]
failure: TFailure | null
Event
Event
<TData>: { data
: TData | null; type
: "SET_DATA" } | { type
: "REFRESH" } | { data
: Partial<TData>; type
: "EDIT" } | { type
: "UNDO" } | { type
: "FETCH" } | { type
: "DELETE" } | { type
: "SUBMIT" }Type Parameters
State
State
<TData, TError, TFailure>: { context
: Core.Nucleon.Context<TData, TError> & { failure
: TFailure }; value
: "fail" } | { context
: Core.Nucleon.Context<TData, TError> & { failure
: null }; value
: "busy" } | { context
: Core.Nucleon.Context<TData, TError> & { failure
: null }; value
: { busy
: "fetching" } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: null; edits
: Partial<TData>; failure
: null }; value
: { busy
: "creating" } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: TData; edits
: Partial<TData>; failure
: null }; value
: { busy
: "updating" } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: TData; failure
: null }; value
: { busy
: "deleting" } } | { context
: Core.Nucleon.Context<TData, TError> & { failure
: null }; value
: "idle" } | { context
: Core.Nucleon.Context<TData, TError> & { data
: TData; failure
: null }; value
: { idle
: "snapshot" } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: TData; edits
: null; failure
: null }; value
: { idle
: { snapshot
: "clean" } } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: TData; edits
: null; failure
: null }; value
: { idle
: { snapshot
: { clean
: "valid" } } } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: TData; edits
: null; failure
: null }; value
: { idle
: { snapshot
: { clean
: "invalid" } } } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: TData; edits
: Partial<TData>; failure
: null }; value
: { idle
: { snapshot
: "dirty" } } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: TData; edits
: Partial<TData>; failure
: null }; value
: { idle
: { snapshot
: { dirty
: "valid" } } } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: TData; edits
: Partial<TData>; failure
: null }; value
: { idle
: { snapshot
: { dirty
: "invalid" } } } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: null; failure
: null }; value
: { idle
: "template" } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: null; edits
: null; failure
: null }; value
: { idle
: { template
: "clean" } } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: null; edits
: null; failure
: null }; value
: { idle
: { template
: { clean
: "valid" } } } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: null; edits
: null; failure
: null }; value
: { idle
: { template
: { clean
: "invalid" } } } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: null; edits
: Partial<TData>; failure
: null }; value
: { idle
: { template
: "dirty" } } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: null; edits
: Partial<TData>; failure
: null }; value
: { idle
: { template
: { dirty
: "valid" } } } } | { context
: Core.Nucleon.Context<TData, TError> & { data
: null; edits
: Partial<TData>; failure
: null }; value
: { idle
: { template
: { dirty
: "invalid" } } } }Type Parameters
TData extends Data = Data
TError = unknown
TFailure = unknown
Variables
Const machine
machine
: StateMachine<Core.Nucleon.Context<Record<string, unknown>, unknown, unknown>, any, Core.Nucleon.Event<Record<string, unknown>>, Core.Nucleon.State<Record<string, unknown>, unknown, unknown>> = ...
Nucleon is a generic state machine for performing CRUD operations on a resource.
States
idle- resource can be edited;template- this is a new resource,context.dataisnull;clean- no edits have been made,context.editsis null;valid-actions.validateallows submitting empty template withservices.sendPost;invalid-actions.validatedisallows submitting empty template withservices.sendPost;dirty- template has been edited,context.editsis notnull;valid-actions.validateallows submitting template withservices.sendPost;invalid-actions.validatedisallows submitting template withservices.sendPost;snapshot- this is an existing resource stored incontext.data;clean- no edits have been made,context.editsis null;valid-actions.validateallows sending PATCH with no changes usingservices.sendPatch;invalid-actions.validaterequires changes before submitting changes withservices.sendPatch;dirty- existing resource has been edited,context.editsis notnull;valid-actions.validateallows submitting edits withservices.sendPatch;invalid-actions.validatedisallows submitting edits withservices.sendPatch;busy- CRUD operation is in progress;fetching-services.sendGetis loading the resource;creating-services.sendPostis creating the resource;updating-services.sendPatchis updating the resource;deleting-services.sendDeleteis deleting the resource;fail- one of the CRUD operations has failedContext
data- loaded resource ornull;edits- changes to the resource incontext.data;errors- array of validation errors, format defined byactions.validate;Events
SET_DATA- setscontext.dataand transitions to the appropriate template or snapshot state;EDIT(idle only) - adds an edit tocontext.editsand transitions to the appropriate valid or invalid state;UNDO(idle only) - removes all edits and transitions to the appropriate valid or invalid state;FETCH- loads a resource by transitioning tobusy.fetchingand runningservices.sendGet;DELETE- deletes a resource by transitioning tobusy.deletingand runningservices.sendDelete;SUBMIT(valid only) - updates or creates a resource;Actions:
validate- runs every time resource changes, put your v8n logic there;Services
sendGet- fetches resource snapshot, returning parsed JSON or throwing an error;sendPost- creates a resource, returning its parsed JSON or throwing an error;sendPatch- updates a resource, returning its full parsed JSON or throwing an error;sendDelete- deletes a resource, returning anything or throwing an error;