Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
use apply()
Browse files Browse the repository at this point in the history
  • Loading branch information
lingyan committed Jan 5, 2015
1 parent 50f2c3a commit e2d52d6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/History.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ History.prototype = {
pushState: function (state, title, url) {
var win = this.win;
if (this._hasPushState) {
win.history.pushState(state, title, url);
win.history.pushState.apply(null, arguments);
} else if (url) {
win.location.href = url;
}
Expand All @@ -90,7 +90,7 @@ History.prototype = {
replaceState: function (state, title, url) {
var win = this.win;
if (this._hasPushState) {
win.history.replaceState(state, title, url);
win.history.replaceState.apply(null, arguments);

This comment has been minimized.

Copy link
@Legogris

Legogris Feb 22, 2015

This breaks the "remember scroll position" in routr, since in that case arguments has only one element and therefore generates (At least in Firefox):
TypeError: Not enough arguments to History.replaceState.

} else if (url) {
win.location.replace(url);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/lib/History-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ describe('History', function () {
it ('has pushState', function () {
var history = new History({win: windowMock.HTML5});

history.pushState({foo: 'bar'});
expect(testResult.pushState.state).to.eql({foo: 'bar'});
expect(testResult.pushState.title).to.equal(undefined);
expect(testResult.pushState.url).to.equal(undefined);

history.pushState({foo: 'bar'}, 't', '/url');
expect(testResult.pushState.state).to.eql({foo: 'bar'});
expect(testResult.pushState.title).to.equal('t');
Expand Down Expand Up @@ -224,6 +229,12 @@ describe('History', function () {
describe('replaceState', function () {
it ('has pushState', function () {
var history = new History({win: windowMock.HTML5});

history.replaceState({foo: 'bar'});
expect(testResult.replaceState.state).to.eql({foo: 'bar'});
expect(testResult.replaceState.title).to.equal(undefined);
expect(testResult.replaceState.url).to.equal(undefined);

history.replaceState({foo: 'bar'}, 't', '/url');
expect(testResult.replaceState.state).to.eql({foo: 'bar'});
expect(testResult.replaceState.title).to.equal('t');
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/utils/HistoryWithHash-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ describe('HistoryWithHash', function () {
it ('useHashRoute=false; has pushState', function () {
var history = new HistoryWithHash({win: windowMock.HTML5});

history.pushState({foo: 'bar'});
expect(testResult.pushState.state).to.eql({foo: 'bar'});
expect(testResult.pushState.title).to.equal(undefined);
expect(testResult.pushState.url).to.equal(undefined);

history.pushState({foo: 'bar'}, 't', '/url');
expect(testResult.pushState.state).to.eql({foo: 'bar'});
expect(testResult.pushState.title).to.equal('t');
Expand Down Expand Up @@ -309,6 +314,12 @@ describe('HistoryWithHash', function () {
describe('replaceState', function () {
it ('useHashRouter=false; has pushState', function () {
var history = new HistoryWithHash({win: windowMock.HTML5});

history.replaceState({foo: 'bar'});
expect(testResult.replaceState.state).to.eql({foo: 'bar'});
expect(testResult.replaceState.title).to.equal(undefined);
expect(testResult.replaceState.url).to.equal(undefined);

history.replaceState({foo: 'bar'}, 't', '/url');
expect(testResult.replaceState.state).to.eql({foo: 'bar'});
expect(testResult.replaceState.title).to.equal('t');
Expand Down
4 changes: 2 additions & 2 deletions utils/HistoryWithHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ HistoryWithHash.prototype = {
}
} else {
if (this._hasPushState) {
history.pushState(state, title, url);
history.pushState.apply(null, arguments);
} else if (url) {
location.href = url;
}
Expand Down Expand Up @@ -170,7 +170,7 @@ HistoryWithHash.prototype = {
}
} else {
if (this._hasPushState) {
history.replaceState(state, title, url);
history.replaceState.apply(null, arguments);
} else if (url) {
location.replace(url);
}
Expand Down

0 comments on commit e2d52d6

Please sign in to comment.