Skip to content

Private to[Member] member not properly setting state #9

@TeknoFiend

Description

@TeknoFiend

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions