state-struct

0.0.4 • Public • Published

StateStruct

immutable structure for state with value, status, error, and timestamp

Example

import State from 'state-struct';
 
let value = State.createEmpty();
let prevValue = value;
 
console.log(value.isEmpty()); // true
value = value.setValue(1); // all modification methods return new object and don`t modify current
console.log(value.isEmpty()); // false
console.log(value.getValue()); // 1
 
console.log(prevValue === value); // false 
value.setValue(2); 
console.log(value.getValue()); // 1 because it`s immutable object 
 
console.log(value.setStatus('LOADING').hasStatus()); // true 
console.log(State.createEmpty().setStatus('LOADING').isEmpty()); // false 
console.log(State.createEmpty().setStatus('LOADING').hasValue()); // false 
 

Package Sidebar

Install

npm i state-struct

Weekly Downloads

0

Version

0.0.4

License

MIT

Last publish

Collaborators

  • fi11