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

Does not always represent the value of path #1

Open
chrisinajar opened this issue May 19, 2016 · 2 comments
Open

Does not always represent the value of path #1

chrisinajar opened this issue May 19, 2016 · 2 comments

Comments

@chrisinajar
Copy link

Since this module relies strictly on popState events to update it's internal value, doing a basic pushState will detach the value from the current state of path.

This only works in the browser because history API

var history = require('observ-history');
var Path = require('observ-path');

history.set('foo');
var path = Path();
// path() => 'foo'
// history() => 'foo'
history.set('bar'); // could also window.location.pushState(null, document.title, 'bar');
// path() => 'foo'
// history() => 'bar'
location.hash = '#'; // causes popState event
// path() => 'bar'
// history() => 'bar'

It's not unreasonable to not emit an event when this happens since the browsers don't, but I would expect path() to always return the current state of the path.

@bendrucker
Copy link
Owner

Can't think of a way to handle this well. I don't want to break from the model of observables and return something when getting the current value that isn't emitted. The only way I can think of to handle this would be to globally path pushState and replaceState which I also don't want to do.

@chrisinajar
Copy link
Author

Yeah neither could I else this would be a pull request :P

I use observ-history directly everywhere, however sour doesn't use the current path when you call render since it still relies on this.

My current solution is a megahack....

  var _set = history.set;
  history.set = function () {
    _set.apply(this, arguments);
    window.location.href = '#';
  };

I really wish browsers emitted a different event when you pushState as opposed to just not emitting anything

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