Skip to content

Instantly share code, notes, and snippets.

@cowboyd cowboyd/example.js
Created Jul 11, 2019

What would you like to do?
A function to execute a transaction on a microstate substate.
let next = over(inventory.item.price, price => price.add(2).add(2).add(2));
import { create, valueOf } from 'microstates';
export default function over(microstate, fn) {
let Type = typeOf(microstate);
let value = valueOf(microstate);
let updated = fn(create(Type, value));
return microstate.set(valueOf(updated));
// this will probably become part of the public API of
// microstates at some point.
function typeOf(microstate) {
return microstate.constructor.Type;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.