Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

preact-router

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

preact-router - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

17

dist/preact-router.js

@@ -250,2 +250,6 @@ (function (global, factory) {

this.setState({ url: url });
// if we're in the middle of an update, don't synchronously re-route.
if (this.updating) return this.canRoute(url);
this.forceUpdate();

@@ -257,4 +261,9 @@ return this._didRoute;

ROUTERS.push(this);
this.updating = true;
};
Router.prototype.componentDidMount = function componentDidMount() {
this.updating = false;
};
Router.prototype.componentWillUnmount = function componentWillUnmount() {

@@ -264,2 +273,10 @@ ROUTERS.splice(ROUTERS.indexOf(this), 1);

Router.prototype.componentWillUpdate = function componentWillUpdate() {
this.updating = true;
};
Router.prototype.componentDidUpdate = function componentDidUpdate() {
this.updating = false;
};
Router.prototype.getMatchingChildren = function getMatchingChildren(children, url, invoke) {

@@ -266,0 +283,0 @@ return children.slice().sort(pathRankSort).filter(function (_ref2) {

2

dist/preact-router.min.js

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("preact")):"function"==typeof define&&define.amd?define(["preact"],e):t.preactRouter=e(t.preact)}(this,function(t){"use strict";function e(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:C,o=/(?:\?([^#]*))?(#.*)?$/,i=t.match(o),u={},a=void 0;if(i&&i[1])for(var c=i[1].split("&"),f=0;f<c.length;f++){var p=c[f].split("=");u[decodeURIComponent(p[0])]=decodeURIComponent(p.slice(1).join("="))}t=n(t.replace(o,"")),e=n(e||"");for(var l=Math.max(t.length,e.length),s=0;s<l;s++)if(e[s]&&":"===e[s].charAt(0)){var h=e[s].replace(/(^\:|[+*?]+$)/g,""),d=(e[s].match(/[+*?]+$/)||C)[0]||"",g=~d.indexOf("+"),v=~d.indexOf("*"),y=t[s]||"";if(!y&&!v&&(d.indexOf("?")<0||g)){a=!1;break}if(u[h]=decodeURIComponent(y),g||v){u[h]=t.slice(s).map(decodeURIComponent).join("/");break}}else if(e[s]!==t[s]){a=!1;break}return(r.default===!0||a!==!1)&&u}function r(t,e){var r=t.attributes||C,n=e.attributes||C;if(r.default)return 1;if(n.default)return-1;var i=o(r.path)-o(n.path);return i||r.path.length-n.path.length}function n(t){return i(t).split("/")}function o(t){return(i(t).match(/\/+/g)||"").length}function i(t){return t.replace(/(^\/+|\/+$)/g,"")}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function c(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function f(t,e){var r={};for(var n in t)e.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n]);return r}function p(t){return j in t}function l(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"push";R&&R[e]?R[e](t):"undefined"!=typeof history&&history[e+"State"]&&history[e+"State"](null,null,t)}function s(){var t=void 0;return t=R&&R.getCurrentLocation?R.getCurrentLocation():"undefined"!=typeof location?location:_,""+(t.pathname||"")+(t.search||"")}function h(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"string"!=typeof t&&t.url&&(e=t.replace,t=t.url),d(t)&&l(t,e?"replace":"push"),g(t)}function d(t){for(var e=w.length;e--;)if(w[e].canRoute(t))return!0;return!1}function g(t){for(var e=!1,r=0;r<w.length;r++)w[r].routeTo(t)===!0&&(e=!0);return e}function v(t){if(t&&t.getAttribute){var e=t.getAttribute("href"),r=t.getAttribute("target");if(e&&e.match(/^\//g)&&(!r||r.match(/^_?self$/i)))return h(e)}}function y(t){if(0===t.button)return v(t.currentTarget||t.target||this),m(t)}function m(t){return t&&(t.stopImmediatePropagation&&t.stopImmediatePropagation(),t.stopPropagation&&t.stopPropagation(),t.preventDefault()),!1}function b(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey)){var e=t.target;do if("A"===String(e.nodeName).toUpperCase()&&e.getAttribute("href")&&p(e)){if(0!==t.button)return;if(v(e))return m(t)}while(e=e.parentNode)}}var C={},O=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},R=null,w=[],_={},j="undefined"!=typeof Symbol?Symbol.for("preactattr"):"__preactattr_";"function"==typeof addEventListener&&(addEventListener("popstate",function(){return g(s())}),addEventListener("click",b));var U=function(e){var r=e.children,n=f(e,["children"]);return t.h("a",O({},n,{onClick:y}),r)},x=function(t){function n(e){u(this,n);var r=a(this,t.call(this,e));return e.history&&(R=e.history),r.state={url:r.props.url||s()},r}return c(n,t),n.prototype.shouldComponentUpdate=function(t){return t.static!==!0||(t.url!==this.props.url||t.onChange!==this.props.onChange)},n.prototype.canRoute=function(t){return this.getMatchingChildren(this.props.children,t,!1).length>0},n.prototype.routeTo=function(t){return this._didRoute=!1,this.setState({url:t}),this.forceUpdate(),this._didRoute},n.prototype.componentWillMount=function(){w.push(this)},n.prototype.componentWillUnmount=function(){w.splice(w.indexOf(this),1)},n.prototype.getMatchingChildren=function(t,n,o){return t.slice().sort(r).filter(function(t){var r=t.attributes,i=r.path,u=e(n,i,r);if(u){if(o!==!1){r.url=n,r.matches=u;for(var a in u)u.hasOwnProperty(a)&&(r[a]=u[a])}return!0}})},n.prototype.render=function(t,e){var r=t.children,n=t.onChange,o=e.url,i=this.getMatchingChildren(r,o,!0),u=i[0]||null;this._didRoute=!!u;var a=this.previousUrl;return o!==a&&(this.previousUrl=o,"function"==typeof n&&n({router:this,url:o,previous:a,active:i,current:u})),u},n}(t.Component),P=function(e){var r=e.component,n=e.url,o=e.matches;return t.h(r,{url:n,matches:o})};return x.route=h,x.Router=x,x.Route=P,x.Link=U,x});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("preact")):"function"==typeof define&&define.amd?define(["preact"],e):t.preactRouter=e(t.preact)}(this,function(t){"use strict";function e(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:C,o=/(?:\?([^#]*))?(#.*)?$/,i=t.match(o),u={},a=void 0;if(i&&i[1])for(var p=i[1].split("&"),c=0;c<p.length;c++){var f=p[c].split("=");u[decodeURIComponent(f[0])]=decodeURIComponent(f.slice(1).join("="))}t=r(t.replace(o,"")),e=r(e||"");for(var l=Math.max(t.length,e.length),s=0;s<l;s++)if(e[s]&&":"===e[s].charAt(0)){var h=e[s].replace(/(^\:|[+*?]+$)/g,""),d=(e[s].match(/[+*?]+$/)||C)[0]||"",g=~d.indexOf("+"),y=~d.indexOf("*"),v=t[s]||"";if(!v&&!y&&(d.indexOf("?")<0||g)){a=!1;break}if(u[h]=decodeURIComponent(v),g||y){u[h]=t.slice(s).map(decodeURIComponent).join("/");break}}else if(e[s]!==t[s]){a=!1;break}return(n.default===!0||a!==!1)&&u}function n(t,e){var n=t.attributes||C,r=e.attributes||C;if(n.default)return 1;if(r.default)return-1;var i=o(n.path)-o(r.path);return i||n.path.length-r.path.length}function r(t){return i(t).split("/")}function o(t){return(i(t).match(/\/+/g)||"").length}function i(t){return t.replace(/(^\/+|\/+$)/g,"")}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function p(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function c(t,e){var n={};for(var r in t)e.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}function f(t){return _ in t}function l(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"push";R&&R[e]?R[e](t):"undefined"!=typeof history&&history[e+"State"]&&history[e+"State"](null,null,t)}function s(){var t=void 0;return t=R&&R.getCurrentLocation?R.getCurrentLocation():"undefined"!=typeof location?location:w,""+(t.pathname||"")+(t.search||"")}function h(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"string"!=typeof t&&t.url&&(e=t.replace,t=t.url),d(t)&&l(t,e?"replace":"push"),g(t)}function d(t){for(var e=U.length;e--;)if(U[e].canRoute(t))return!0;return!1}function g(t){for(var e=!1,n=0;n<U.length;n++)U[n].routeTo(t)===!0&&(e=!0);return e}function y(t){if(t&&t.getAttribute){var e=t.getAttribute("href"),n=t.getAttribute("target");if(e&&e.match(/^\//g)&&(!n||n.match(/^_?self$/i)))return h(e)}}function v(t){if(0===t.button)return y(t.currentTarget||t.target||this),m(t)}function m(t){return t&&(t.stopImmediatePropagation&&t.stopImmediatePropagation(),t.stopPropagation&&t.stopPropagation(),t.preventDefault()),!1}function b(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey)){var e=t.target;do if("A"===String(e.nodeName).toUpperCase()&&e.getAttribute("href")&&f(e)){if(0!==t.button)return;if(y(e))return m(t)}while(e=e.parentNode)}}var C={},O=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},R=null,U=[],w={},_="undefined"!=typeof Symbol?Symbol.for("preactattr"):"__preactattr_";"function"==typeof addEventListener&&(addEventListener("popstate",function(){return g(s())}),addEventListener("click",b));var j=function(e){var n=e.children,r=c(e,["children"]);return t.h("a",O({},r,{onClick:v}),n)},x=function(t){function r(e){u(this,r);var n=a(this,t.call(this,e));return e.history&&(R=e.history),n.state={url:n.props.url||s()},n}return p(r,t),r.prototype.shouldComponentUpdate=function(t){return t.static!==!0||(t.url!==this.props.url||t.onChange!==this.props.onChange)},r.prototype.canRoute=function(t){return this.getMatchingChildren(this.props.children,t,!1).length>0},r.prototype.routeTo=function(t){return this._didRoute=!1,this.setState({url:t}),this.updating?this.canRoute(t):(this.forceUpdate(),this._didRoute)},r.prototype.componentWillMount=function(){U.push(this),this.updating=!0},r.prototype.componentDidMount=function(){this.updating=!1},r.prototype.componentWillUnmount=function(){U.splice(U.indexOf(this),1)},r.prototype.componentWillUpdate=function(){this.updating=!0},r.prototype.componentDidUpdate=function(){this.updating=!1},r.prototype.getMatchingChildren=function(t,r,o){return t.slice().sort(n).filter(function(t){var n=t.attributes,i=n.path,u=e(r,i,n);if(u){if(o!==!1){n.url=r,n.matches=u;for(var a in u)u.hasOwnProperty(a)&&(n[a]=u[a])}return!0}})},r.prototype.render=function(t,e){var n=t.children,r=t.onChange,o=e.url,i=this.getMatchingChildren(n,o,!0),u=i[0]||null;this._didRoute=!!u;var a=this.previousUrl;return o!==a&&(this.previousUrl=o,"function"==typeof r&&r({router:this,url:o,previous:a,active:i,current:u})),u},r}(t.Component),P=function(e){var n=e.component,r=e.url,o=e.matches;return t.h(n,{url:r,matches:o})};return x.route=h,x.Router=x,x.Route=P,x.Link=j,x});
//# sourceMappingURL=preact-router.min.js.map
{
"name": "preact-router",
"amdName": "preactRouter",
"version": "2.2.0",
"version": "2.3.0",
"description": "Connect your components up to that address bar.",

@@ -6,0 +6,0 @@ "main": "dist/preact-router.js",

@@ -162,2 +162,6 @@ import { h, Component } from 'preact';

this.setState({ url });
// if we're in the middle of an update, don't synchronously re-route.
if (this.updating) return this.canRoute(url);
this.forceUpdate();

@@ -169,4 +173,9 @@ return this._didRoute;

ROUTERS.push(this);
this.updating = true;
}
componentDidMount() {
this.updating = false;
}
componentWillUnmount() {

@@ -176,2 +185,10 @@ ROUTERS.splice(ROUTERS.indexOf(this), 1);

componentWillUpdate() {
this.updating = true;
}
componentDidUpdate() {
this.updating = false;
}
getMatchingChildren(children, url, invoke) {

@@ -178,0 +195,0 @@ return children.slice().sort(pathRankSort).filter( ({ attributes }) => {

@@ -122,3 +122,35 @@ import { Router, Link, route } from 'src';

});
it('should support re-routing', done => {
class A {
componentWillMount() {
route('/b');
}
render(){ return <div class="a" />; }
}
class B {
componentWillMount(){}
render(){ return <div class="b" />; }
}
sinon.spy(A.prototype, 'componentWillMount');
sinon.spy(B.prototype, 'componentWillMount');
mount(
<Router>
<A path="/a" />
<B path="/b" />
</Router>
);
expect(A.prototype.componentWillMount).not.to.have.been.called;
route('/a');
expect(A.prototype.componentWillMount).to.have.been.calledOnce;
A.prototype.componentWillMount.reset();
expect(location.pathname).to.equal('/b');
setTimeout( () => {
expect(A.prototype.componentWillMount).not.to.have.been.called;
expect(B.prototype.componentWillMount).to.have.been.calledOnce;
expect(scratch).to.have.deep.property('firstElementChild.className', 'b');
done();
}, 10);
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc