cyclejs / history

MOVED
59 stars 8 forks source link

`makeHistoryDriver` should output the initial location. #10

Closed b31jung closed 8 years ago

b31jung commented 8 years ago

From my understanding, from Cycle.js's viewpoint, imperative APIs such as history.replace should be run through drivers. I think that's why the location object accessible from source observable has some additional functions, like location.replace or location.goBack. However, I found the initial location is not emitted for 1.1.0, which means I should access the history object myself outside of drivers to use such functions on the initial page. I tried working around like this,

function makeStartedHistoryDriver() {
  return url$ => {
    let driver = makeHistoryDriver();
    return driver(
      url$.startWith(window.location.pathname)
    );
  };
}

but this duplicates the initial location in history list. (window.location.pathname pushed unnecessarily) Am I properly understanding the framework?

b31jung commented 8 years ago

After investigating the code for a while, I realized the functions like replace get attached to the observable, not to the location objects. I misunderstood this paragraph,

In return you will be given an Rx.Observable with the current Location. With some extra functions appended.The functions appended to the returned Observable can be found here. All of those functions are exposed except for listen(). (https://github.com/cyclejs/cycle-history/blob/master/docs/historyDriver.md)

So there's no problem with accessing the functionalities inside an app. Sorry for the issue :(