Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean State #8

Closed
cowboyd opened this issue Aug 23, 2016 · 5 comments
Closed

Boolean State #8

cowboyd opened this issue Aug 23, 2016 · 5 comments
Milestone

Comments

@cowboyd
Copy link
Member

cowboyd commented Aug 23, 2016

The microstate primitive Bool wraps a simple boolean value.

No matter what you pass to the constructor, it is naturally coerced into a boolean value:

new Bool(true).valueOf() //=> true
new Bool(false).valueOf() //=> false
new Bool("Ohai") //=> true
new Bool(null) //=> false

The same applies if you set a boolean value to explicit value:

new Bool(false).set("Ohai").valueOf() //=> true
new Bool(true).set(null).valueOf() //=> false

The only other transition available on a boolean value is toggle:

new Bool(true).toggle().valueOf() //=> false
new Bool(false).toggle().valueOf() //=> true
@cowboyd cowboyd mentioned this issue Aug 23, 2016
12 tasks
@cowboyd cowboyd added this to the 0.1.0 milestone Aug 23, 2016
@taras
Copy link
Member

taras commented Sep 2, 2016

@cowboyd for new Bool(false).set("Ohai").valueOf(), does the value become Ohai or is it coerced to a boolean at creation?

@cowboyd
Copy link
Member Author

cowboyd commented Sep 2, 2016

You've pointed to an important use-case

new Bool(false).set("Ohai").valueOf() //=> true

It will be coerced in the sense that all values passed to set are passed as arguments to the "constructor" function. Don't know what the syntax will be yet, but probably:

const Bool = State.extend({
  construct(value) {
    return !!value;
  }
});

@taras
Copy link
Member

taras commented Sep 2, 2016

you mean, constructor(value) { return !!value; } right?

I tried to implement Bool but it doesn't seem to call the constructor function yet. Is there something missing from implementation to do this yet?

@cowboyd
Copy link
Member Author

cowboyd commented Sep 2, 2016

Yes, it has not been added yet, so you will have to coerce the value manually for now. We could call it constructor, but I am a bit worried that it might be confused as the es6 constructor, and it does need a return value.

@cowboyd
Copy link
Member Author

cowboyd commented Sep 2, 2016

initialize(), box(), coerce() might be other options.

@taras taras closed this as completed Aug 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants