cerebral / addressbar

Makes the addressbar of the browser work just like a normal input
MIT License
84 stars 8 forks source link

expose ability to replace state #4

Closed Guria closed 9 years ago

Guria commented 9 years ago

variant 1

addressbar.replace(newUrl);

variant 2

addressbar.replaceNext();
addressbar.value = newUrl;

variant 3

addressbar.value = '!' + newUrl;
christianalfoni commented 9 years ago

Thanks for the suggestions and thinking "out of the box" :-)

I have a feeling we just have to expose a method for this, as your first suggestion. But lets play with this some more first.

addressbar.value = {
  url: newUrl,
  replace: true
};

Which could also be used to:

addressbar.value = {
  url: newUrl,
  replace: true,
  hash: true,
  query: myQuery
};

I kinda like this, as it opens up even new doors. What do you think?

Guria commented 9 years ago

Hmm. I like this. Should we still support string values?

christianalfoni commented 9 years ago

Hm, good question. My initial thought is "yes". That is like default behaviour. But since this is somewhat a magic input it also supports an object as a value :-)

Guria commented 9 years ago

There is another question: console.log(addressbar.value)?

Guria commented 9 years ago

Ok, I think then addressbar.value is string by default, but accepts object in setter?

christianalfoni commented 9 years ago

That is also a good point. I think actually we should return the string now. To avoid any migration issues. Then we get some experience with it and can make a better decision on maybe stripping out strings completely or other alternatives.

Guria commented 9 years ago

@christianalfoni I think I'll leave this task for you. I am afraid I will not write adequate tests in this project in short time.

      if (typeof value === "object") {
        doReplace = !!value.replace;
        value = value.url;
      }
christianalfoni commented 9 years ago

Cool, lets conclude with allowing an object to be set like this:

addressbar.value = {
  value: url,
  replace: true
}

To force replacing the url. This allows for expanding and does not require any migration path. I will make this part of the next cerebral-router release package :-)

Guria commented 9 years ago

we need it before router new relese so we could test routers redirect

christianalfoni commented 9 years ago

Jup, will do that

christianalfoni commented 9 years ago

Okay, got it running with test and updated documentation

christianalfoni commented 9 years ago

released