Skip to content

Commit

Permalink
fix: prevent multiple wrap calls;
Browse files Browse the repository at this point in the history
- Closes #8
- Adds 8 bytes
  • Loading branch information
lukeed committed Jun 3, 2019
1 parent 77fa92d commit 0f5b5bb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ export default function Navaid(base, on404) {
}

function wrap(type, fn) {
type += 'State';
fn = history[type];
if (history[type]) return;
history[type] = type;
fn = history[type += 'State'];
history[type] = function (uri) {

This comment has been minimized.

Copy link
@jacwright

jacwright Jun 3, 2019

Contributor

history[type] = type; is overwritten by history[type] = function (uri) { 2 lines later so can be removed, removing 22 bytes.

This comment has been minimized.

Copy link
@lukeed

lukeed Jun 3, 2019

Author Owner

The += 'State' evaluates first, before the second history[type] is written.

history['push'] = 'push';
fn = history['pushState'];
history['pushState'] = function (uri) {
  // ...
}

This comment has been minimized.

Copy link
@jacwright

jacwright Jun 3, 2019

Contributor

I missed the +=. :D optimized code can be hard to read I'm finding.

var ev = new Event(type.toLowerCase());
ev.uri = uri;
Expand Down

0 comments on commit 0f5b5bb

Please sign in to comment.