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

Support drivers that use startWith #30

Open
Widdershin opened this issue Feb 3, 2016 · 2 comments
Open

Support drivers that use startWith #30

Widdershin opened this issue Feb 3, 2016 · 2 comments
Milestone

Comments

@Widdershin
Copy link
Owner

No description provided.

@Widdershin Widdershin added this to the v1 milestone Feb 25, 2016
@ronag
Copy link
Contributor

ronag commented Mar 3, 2016

What are the implications?

@Widdershin
Copy link
Owner Author

I have this keys driver in one of my projects:

function makeKeysDriver () {
  const keydown$ = Observable.fromEvent(document, 'keydown');
  const keyup$ = Observable.fromEvent(document, 'keyup');

  function isKey (key) {
    return (event) => {
      return event.keyCode === key;
    }
  }

  return function keysDriver () {
    return {
      isDown: (key) => {
        return Observable.merge(
          keydown$.filter(isKey(key)).map(_ => true),
          keyup$.filter(isKey(key)).map(_ => false)
        ).startWith(false)
      }
    }
  }
}

Note the startWith(false). cycle-restart subscribes to this driver, but before the application has subscribed, so the initial false value never makes it to the app. As such, I have to press all the keys I've subscribed to before a combineLatest will actually start up.

It's really a hot vs cold thing. It just so happens that the majority of drivers are hot so mostly there isn't an impact.

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