preact-router
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -1,3 +0,3 @@ | ||
(function(global,factory){if(typeof define === 'function' && define.amd){define(['exports','preact'],factory);}else if(typeof exports !== 'undefined'){factory(exports,require('preact'));}else {var mod={exports:{}};factory(mod.exports,global.preact);global.preactRouter = mod.exports;}})(this,function(exports,_preact){'use strict';exports.__esModule = true;var _extends=Object.assign || function(target){for(var i=1;i < arguments.length;i++) {var source=arguments[i];for(var key in source) {if(Object.prototype.hasOwnProperty.call(source,key)){target[key] = source[key];}}}return target;};exports.route = route;function _objectWithoutProperties(obj,keys){var target={};for(var i in obj) {if(keys.indexOf(i) >= 0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i] = obj[i];}return target;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function');}}function _inherits(subClass,superClass){if(typeof superClass !== 'function' && superClass !== null){throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var routers=[];function route(url){if(history){history.pushState(null,null,url);}routeTo(url);}function routeTo(url){routers.forEach(function(router){return router.routeTo(url);});}function getCurrentUrl(){return '' + (location.pathname || '') + (location.search || '');}if(typeof addEventListener === 'function'){addEventListener('popstate',function(){return routeTo(getCurrentUrl());});}function handleLinkClick(e){route(this.getAttribute('href'));if(e.stopImmediatePropagation)e.stopImmediatePropagation();e.stopPropagation();e.preventDefault();return false;}var Link=function Link(_ref){var children=_ref.children;var props=_objectWithoutProperties(_ref,['children']);return _preact.h('a',_extends({},props,{onClick:handleLinkClick}),children);};exports.Link = Link;var Router=(function(_Component){_inherits(Router,_Component);function Router(){_classCallCheck(this,Router);_Component.apply(this,arguments);}Router.prototype.getInitialState = function getInitialState(){return {url:getCurrentUrl()};};Router.prototype.routeTo = function routeTo(url){this.setState({url:url});};Router.prototype.componentWillMount = function componentWillMount(){routers.push(this);};Router.prototype.componentWillUnmount = function componentWillUnmount(){routers.splice(routers.indexOf(this),1);};Router.prototype.render = function render(_ref2,_ref3){var children=_ref2.children;var onChange=_ref2.onChange;var url=_ref3.url;var active=children.filter(function(_ref4){var attributes=_ref4.attributes;var path=attributes.path,matches=exec(url,path);if(matches){attributes.url = url;attributes.matches = matches;return true;}});var previous=this.previousUrl;if(url !== previous){this.previousUrl = url;if(typeof onChange === 'function'){onChange({router:this,url:url,previous:previous,active:active,current:active[0]});}}return _preact.h('router',{style:'position:static;display:inline;'},active);};return Router;})(_preact.Component);exports.Router = Router;var Route=function Route(_ref5){var RoutedComponent=_ref5.component;var url=_ref5.url;var matches=_ref5.matches;return _preact.h(RoutedComponent,{url:url,matches:matches});};exports.Route = Route;function exec(url,route){var reg=/(?:\?([^#]*))?(#.*)?$/,c=url.match(reg),matches={};if(c && c[1]){var p=c[1].split('&');for(var i=0;i < p.length;i++) {var r=p[i].split('=');matches[decodeURIComponent(r[0])] = decodeURIComponent(r.slice(1).join('='));}}url = segmentize(url.replace(reg,''));route = segmentize(route);var max=Math.max(url.length,route.length);for(var i=0;i < max;i++) {if(route[i] && route[i].charAt(0) === ':'){matches[route[i].substring(1)] = decodeURIComponent(url[i] || '');}else {if(route[i] !== url[i]){return false;}}}return matches;}Router.route = route;Router.Route = Route;Router.Link = Link;exports['default'] = Router;var segmentize=function segmentize(url){return strip(url).split('/');};var strip=function strip(url){return url.replace(/(^\/+|\/+$)/g,'');};}); | ||
(function(global,factory){if(typeof define === 'function' && define.amd){define(['exports','preact'],factory);}else if(typeof exports !== 'undefined'){factory(exports,require('preact'));}else {var mod={exports:{}};factory(mod.exports,global.preact);global.preactRouter = mod.exports;}})(this,function(exports,_preact){'use strict';exports.__esModule = true;var _extends=Object.assign || function(target){for(var i=1;i < arguments.length;i++) {var source=arguments[i];for(var key in source) {if(Object.prototype.hasOwnProperty.call(source,key)){target[key] = source[key];}}}return target;};exports.route = route;function _objectWithoutProperties(obj,keys){var target={};for(var i in obj) {if(keys.indexOf(i) >= 0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i] = obj[i];}return target;}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function');}}function _inherits(subClass,superClass){if(typeof superClass !== 'function' && superClass !== null){throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__ = superClass;}var routers=[];function route(url){if(history){history.pushState(null,null,url);}routeTo(url);}function routeTo(url){routers.forEach(function(router){return router.routeTo(url);});}function getCurrentUrl(){return '' + (location.pathname || '') + (location.search || '');}if(typeof addEventListener === 'function'){addEventListener('popstate',function(){return routeTo(getCurrentUrl());});}function handleLinkClick(e){route(this.getAttribute('href'));if(e.stopImmediatePropagation)e.stopImmediatePropagation();e.stopPropagation();e.preventDefault();return false;}var Link=function Link(_ref){var children=_ref.children;var props=_objectWithoutProperties(_ref,['children']);return _preact.h('a',_extends({},props,{onClick:handleLinkClick}),children);};exports.Link = Link;var Router=(function(_Component){_inherits(Router,_Component);function Router(){_classCallCheck(this,Router);_Component.apply(this,arguments);}Router.prototype.getInitialState = function getInitialState(){return {url:getCurrentUrl()};};Router.prototype.routeTo = function routeTo(url){this.setState({url:url});};Router.prototype.componentWillMount = function componentWillMount(){routers.push(this);};Router.prototype.componentWillUnmount = function componentWillUnmount(){routers.splice(routers.indexOf(this),1);};Router.prototype.render = function render(_ref2,_ref3){var children=_ref2.children;var onChange=_ref2.onChange;var url=_ref3.url;var active=children.filter(function(_ref4){var attributes=_ref4.attributes;var path=attributes.path,matches=exec(url,path);if(matches){attributes.url = url;attributes.matches = matches;for(var i in matches) {if(matches.hasOwnProperty(i) && !attributes.hasOwnProperty(i)){attributes[i] = matches[i];}}return true;}});var previous=this.previousUrl;if(url !== previous){this.previousUrl = url;if(typeof onChange === 'function'){onChange({router:this,url:url,previous:previous,active:active,current:active[0]});}}return _preact.h('router',{style:'position:static;display:inline;'},active);};return Router;})(_preact.Component);exports.Router = Router;var Route=function Route(_ref5){var RoutedComponent=_ref5.component;var url=_ref5.url;var matches=_ref5.matches;return _preact.h(RoutedComponent,{url:url,matches:matches});};exports.Route = Route;function exec(url,route){var reg=/(?:\?([^#]*))?(#.*)?$/,c=url.match(reg),matches={};if(c && c[1]){var p=c[1].split('&');for(var i=0;i < p.length;i++) {var r=p[i].split('=');matches[decodeURIComponent(r[0])] = decodeURIComponent(r.slice(1).join('='));}}url = segmentize(url.replace(reg,''));route = segmentize(route);var max=Math.max(url.length,route.length);for(var i=0;i < max;i++) {if(route[i] && route[i].charAt(0) === ':'){matches[route[i].substring(1)] = decodeURIComponent(url[i] || '');}else {if(route[i] !== url[i]){return false;}}}return matches;}Router.route = route;Router.Route = Route;Router.Link = Link;exports['default'] = Router;var segmentize=function segmentize(url){return strip(url).split('/');};var strip=function strip(url){return url.replace(/(^\/+|\/+$)/g,'');};}); | ||
//# sourceMappingURL=preact-router.js.map |
{ | ||
"name": "preact-router", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Connect your components up to that address bar.", | ||
@@ -5,0 +5,0 @@ "main": "dist/preact-router.js", |
@@ -63,2 +63,8 @@ import { h, Component } from 'preact'; | ||
attributes.matches = matches; | ||
// copy matches onto props without overwriting anything already there | ||
for (let i in matches) { | ||
if (matches.hasOwnProperty(i) && !attributes.hasOwnProperty(i)) { | ||
attributes[i] = matches[i]; | ||
} | ||
} | ||
return true; | ||
@@ -65,0 +71,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18503
144