Comparing version 1.4.3 to 1.5.0
@@ -383,2 +383,5 @@ 'use strict'; | ||
if (this.router) { | ||
this.router.unregisterListeners(); | ||
} | ||
if (this.$panelParent) { | ||
@@ -385,0 +388,0 @@ this.$panelParent.$panelChildren.delete(this); |
@@ -23,4 +23,2 @@ "use strict"; | ||
function Router(app) { | ||
var _this = this; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -31,3 +29,3 @@ | ||
// allow injecting window dep | ||
var routerWindow = this.window = options.window || window; | ||
this.window = options.window || window; | ||
@@ -61,18 +59,33 @@ this.app = app; | ||
var navigateToHash = function navigateToHash() { | ||
return _this.navigate(routerWindow.location.hash); | ||
}; | ||
routerWindow.addEventListener("popstate", function () { | ||
return navigateToHash(); | ||
}); | ||
this.historyMethod = options.historyMethod || "pushState"; | ||
var origChangeState = routerWindow.history[this.historyMethod]; | ||
routerWindow.history[this.historyMethod] = function () { | ||
origChangeState.apply(routerWindow.history, arguments); | ||
navigateToHash(); | ||
}; | ||
this.registerListeners(options.historyMethod || "pushState"); | ||
} | ||
_createClass(Router, [{ | ||
key: "registerListeners", | ||
value: function registerListeners(historyMethod) { | ||
var _this = this; | ||
this.navigateToHash = function () { | ||
return _this.navigate(_this.window.location.hash); | ||
}; | ||
this.window.addEventListener("popstate", this.navigateToHash); | ||
this.historyMethod = historyMethod; | ||
this.origChangeStateMethod = this.window.history[this.historyMethod]; | ||
this.window.history[this.historyMethod] = function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this.origChangeStateMethod.apply(_this.window.history, args); | ||
_this.navigateToHash(); | ||
}; | ||
} | ||
}, { | ||
key: "unregisterListeners", | ||
value: function unregisterListeners() { | ||
this.window.removeEventListener("popstate", this.navigateToHash); | ||
this.window.history[this.historyMethod] = this.origChangeStateMethod; | ||
} | ||
}, { | ||
key: "navigate", | ||
@@ -79,0 +92,0 @@ value: function navigate(fragment) { |
@@ -314,2 +314,5 @@ import cuid from 'cuid'; | ||
if (this.router) { | ||
this.router.unregisterListeners(); | ||
} | ||
if (this.$panelParent) { | ||
@@ -316,0 +319,0 @@ this.$panelParent.$panelChildren.delete(this); |
@@ -9,3 +9,3 @@ function stripHash(fragment) { | ||
// allow injecting window dep | ||
const routerWindow = this.window = options.window || window; | ||
this.window = options.window || window; | ||
@@ -41,13 +41,22 @@ this.app = app; | ||
const navigateToHash = () => this.navigate(routerWindow.location.hash); | ||
routerWindow.addEventListener(`popstate`, () => navigateToHash()); | ||
this.registerListeners(options.historyMethod || `pushState`); | ||
} | ||
this.historyMethod = options.historyMethod || `pushState`; | ||
const origChangeState = routerWindow.history[this.historyMethod]; | ||
routerWindow.history[this.historyMethod] = function() { | ||
origChangeState.apply(routerWindow.history, arguments); | ||
navigateToHash(); | ||
registerListeners(historyMethod) { | ||
this.navigateToHash = () => this.navigate(this.window.location.hash); | ||
this.window.addEventListener(`popstate`, this.navigateToHash); | ||
this.historyMethod = historyMethod; | ||
this.origChangeStateMethod = this.window.history[this.historyMethod]; | ||
this.window.history[this.historyMethod] = (...args) => { | ||
this.origChangeStateMethod.apply(this.window.history, args); | ||
this.navigateToHash(); | ||
}; | ||
} | ||
unregisterListeners() { | ||
this.window.removeEventListener(`popstate`, this.navigateToHash); | ||
this.window.history[this.historyMethod] = this.origChangeStateMethod; | ||
} | ||
navigate(fragment, stateUpdate={}) { | ||
@@ -54,0 +63,0 @@ fragment = stripHash(fragment); |
{ | ||
"name": "panel", | ||
"version": "1.4.3", | ||
"version": "1.5.0", | ||
"description": "Web Components with Virtual DOM: lightweight composable web apps", | ||
@@ -23,3 +23,3 @@ "main": "build/index.js", | ||
"test-browser-sauce": "wct --plugin sauce test/browser/index.html", | ||
"test-server": "NODE_ENV=test mocha --require babel-core/register --require babel-polyfill test/server", | ||
"test-server": "NODE_ENV=test mocha --require babel-core/register test/server", | ||
"ts-check": "tsc", | ||
@@ -66,2 +66,3 @@ "tslint": "tslint -c tslint.json -t stylish 'lib/index.d.ts'" | ||
"chrome-store-api": "1.0.5", | ||
"domsuite": "0.2.0", | ||
"eslint": "4.18.1", | ||
@@ -68,0 +69,0 @@ "eslint-config-mixpanel": "3.5.0", |
@@ -70,3 +70,3 @@ # panel | ||
Browser tests run with Selenium through [web-component-tester](https://github.com/Polymer/web-component-tester). Server-side rendering tests use `mocha` and `chai` directly. | ||
Browser tests run with Selenium through [web-component-tester](https://github.com/Polymer/tools/tree/master/packages/web-component-tester). Server-side rendering tests use `mocha` and `chai` directly. | ||
@@ -73,0 +73,0 @@ #### Run with locally installed browsers |
2670
120624
23
31