The example in the README wasn't working for me so I modified it a bit to extract some info about what is happening. I believe I'm doing this correctly.
The initial state value is "foo". After the resolve call the state value appears to be a String type representation.
const PromiseType = Union({
Pending: PromiseType => class extends PromiseType {
resolve(result) {
return this.toResolved(result);
}
},
Resolved: PromiseType => class extends PromiseType {},
});
let p = PromiseType.Pending.create("foo");
console.log( p.isPending, p.isResolved ); // => true false
console.log( p.state ); // => foo
p = p.resolve("great!");
console.log( p.isPending, p.isResolved ); // => false true
console.log( p.state ); // =>
// String {length: 3}
// 0: (...)
// 1: (...)
// 2: (...)
// 3: (...)
// 4: (...)
// length: 3
// get 0: ƒ ()
// get 1: ƒ ()
// get 2: ƒ ()
// get 3: ƒ ()
// get 4: ƒ ()
// __proto__: String
I hope this is helpful.
The example in the README wasn't working for me so I modified it a bit to extract some info about what is happening. I believe I'm doing this correctly.
The initial state value is
"foo". After theresolvecall the state value appears to be aStringtype representation.I hope this is helpful.