@satellite-earth/state v2.0.0
View full documentation at https://docs.satellite.earth/
Usage
const state = new State({
name: 'mystate',
established: 10195635
});
Constructor
Object
- State meta dataname
-String
- Name of the stateestablished
-Number
- Block number at which state was created
Properties
store
state.store
Object
- Arbitrary data model
nucleus
state.nucleus
Object
- Contains state's get
and set
logic
record
state.record
Object
- Map of signal uuid
to blockNumber
at which that signal updated the state
established
state.established // 1591149129
Number
- Block number at which state was created
updated
state.updated // 10202992
Number
- Last block number at which state was modified
compressed
state.compressed
Uint8Array
- Compressed state data
initialized
state.initialized // true
Boolean
- If store
has been created
Methods
data
await state.data(data);
Build state from compressed data. Overrides method on Torrent superclass.
Parameters
Uint8Array
- State torrent data
Returns
Promise
returns this
- Reference to self allows method chaining
build
await state.build();
Recompute data params for present state
Returns
Promise
returns this
- Reference to self allows method chaining
set
state.set(signal, epoch);
Modify state's data store method with signal data as interpreted by the state's internal logic.
Parameters
Signal
- Signal objectObject
- Epoch contextsigner
-String
- Alias name of epoch signernumber
-Number
- Ordinal epoch numberalpha
-Number
- Block number from which epoch began
Object
- Optionssafe
-Boolean
- If copy of the store should be made prior to modification to prevent unintentional partial modification of the data by setter logic. The tradeoff for usingsafe
mode is decreased performance since a copy of the store has to made on every update. Not recommended for production, but useful for debugging.
get
const myValue = state.get('foo', { bar: 'baz' });
Read data from the state's internal store by interfacing with the state's internal getter logic.
Parameters
String
- Name of thing to get (passed to internal getter)Object
- Arbitary query params (passed to internal getter)Object
- Optionssafe
- Boolean - If copy of the store should be made prior to reading data to prevent unintentional modification by getter logic. Comes with a performance hit (see above)
Returns
?
- Unknown return type (depends on internal getter)
on
state.on('myevent', (data) => {
// . . .
});
Attach an event handler to react to custom events triggered by the internal setter function.
Parameters
String
- Name of eventFunction
- Handler called with data provided by internal setter