update Types and Type Composition code sample in README
eandy5000 opened this issue · 2 comments
eandy5000 commented
I'd like to suggest an edit to Types and Type Composition code sample in README. For Array and Object it shows foo.state and numbers.state which returns undefined. I put my suggested update below which uses valueOf instead.
import { create, valueOf } from "microstates";
let meaningOfLifeAndEverything = create(Number, 42);
console.log(meaningOfLifeAndEverything.state);
//> 42
let greeting = create(String, "Hello World");
console.log(greeting.state);
//> Hello World
let isOpen = create(Boolean, true);
console.log(isOpen.state);
//> true
// For Object and Array use microstates valueOf method
let foo = create(Object, { foo: "bar" });
console.log(valueOf(foo));
//> { foo: 'bar' }
let numbers = create(Array, [1, 2, 3, 4]);
console.log(valueOf(numbers));
//> [ 1, 2, 3, 4 ]
taras commented
Hi Andy, thank you for your suggestion. It looks good. Please, make a PR so with your suggestion so I can merge it in.