From f19c21ad885500e4d7ac1b29d21960d814caa3fb Mon Sep 17 00:00:00 2001 From: Forestdev Date: Thu, 9 Jun 2016 14:29:12 +0200 Subject: [PATCH] Mild refactoring of default exports & method renaming --- dist/jsRoute.js | 32 ++++++++++++++++---------------- dist/jsRoute.min.js | 2 +- dist/jsRoute.noamd.js | 32 ++++++++++++++++---------------- dist/jsRoute.noamd.min.js | 2 +- example/jsRoute.js | 32 ++++++++++++++++---------------- src/events/eventHandler.ts | 2 +- src/history/history.ts | 4 ++-- src/location/location.model.ts | 7 +++---- src/route/route.model.ts | 2 +- src/route/route.observer.ts | 6 +++--- src/route/route.provider.ts | 2 +- src/router/router.events.ts | 10 +++++----- 12 files changed, 66 insertions(+), 67 deletions(-) diff --git a/dist/jsRoute.js b/dist/jsRoute.js index 4ffaf8d..d8ae30b 100644 --- a/dist/jsRoute.js +++ b/dist/jsRoute.js @@ -443,7 +443,8 @@ define("../node_modules/almond/almond", function(){}); _event = new CustomEvent(eventName, eventData); element.dispatchEvent(_event); } - exports.broadcastEvent = broadcastEvent; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = broadcastEvent; }); //# sourceMappingURL=../../src/tmp/maps/events/eventHandler.js.map; (function (factory) { @@ -514,18 +515,18 @@ define("../node_modules/almond/almond", function(){}); this.matchingPath = ''; } $Location.prototype.path = function (href) { - router_events_1.startRouteChange(constructRoute(href)); + router_events_1.startRouteChange(routeFactory(href)); }; return $Location; }()); - exports.$Location = $Location; - function constructRoute(url) { + function routeFactory(url) { var prev = window.location; var next = new $Location(url); var locationList = { next: next, prev: prev }; return locationList; } - exports.constructRoute = constructRoute; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = routeFactory; }); //# sourceMappingURL=../../src/tmp/maps/location/location.model.js.map; (function (factory) { @@ -537,17 +538,17 @@ define("../node_modules/almond/almond", function(){}); } })(function (require, exports) { 'use strict'; - var eventHandler = require('../events/eventHandler'); + var eventHandler_1 = require('../events/eventHandler'); var location_model_1 = require('../location/location.model'); var utils = require('../utils/utils'); function onRun() { - startRouteChange(location_model_1.constructRoute(window.location.origin + window.location.pathname)); + startRouteChange(location_model_1.default(window.location.origin + window.location.pathname)); } exports.onRun = onRun; function startRouteChange(location) { var root = utils.getRoot(); var locationList = location; - eventHandler.broadcastEvent('routeChange', root, { detail: locationList }); + eventHandler_1.default('routeChange', root, { detail: locationList }); } exports.startRouteChange = startRouteChange; function interceptLinks() { @@ -555,7 +556,7 @@ define("../node_modules/almond/almond", function(){}); root.addEventListener('click', function (ev) { if (ev.target.nodeName === 'A') { ev.preventDefault(); - startRouteChange(location_model_1.constructRoute(ev.target.href)); + startRouteChange(location_model_1.default(ev.target.href)); } }); } @@ -624,7 +625,7 @@ define("../node_modules/almond/almond", function(){}); window.addEventListener('popstate', function (ev) { ev.preventDefault(); popStateInvoked = true; - router_events_1.startRouteChange(location_model_1.constructRoute(ev.state.path)); + router_events_1.startRouteChange(location_model_1.default(ev.state.path)); }); } exports.monitorBrowserNavigation = monitorBrowserNavigation; @@ -660,10 +661,8 @@ define("../node_modules/almond/almond", function(){}); return callback(); } view.innerHTML = data; - if (route.options.cache) { - if (!isCached) { - route.storeTemplateToCache(data); - } + if (route.options.cache && !isCached) { + route.storeTemplateToCache(data); } return callback(null, true); }); @@ -782,7 +781,8 @@ define("../node_modules/almond/almond", function(){}); }; return Route; }()); - exports.Route = Route; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = Route; }); //# sourceMappingURL=../../src/tmp/maps/route/route.model.js.map; (function (factory) { @@ -798,7 +798,7 @@ define("../node_modules/almond/almond", function(){}); var observer = require('./route.observer'); var provider = { when: function (path, options) { - var route = new route_model_1.Route(path, options); + var route = new route_model_1.default(path, options); observer.addRoute(route); return this; }, diff --git a/dist/jsRoute.min.js b/dist/jsRoute.min.js index d2eb009..326fa3f 100644 --- a/dist/jsRoute.min.js +++ b/dist/jsRoute.min.js @@ -1 +1 @@ -!function(a){var b,c,d;!function(a){function e(a,b){return u.call(a,b)}function f(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o=b&&b.split("/"),p=s.map,q=p&&p["*"]||{};if(a){for(a=a.split("/"),g=a.length-1,s.nodeIdCompat&&w.test(a[g])&&(a[g]=a[g].replace(w,"")),"."===a[0].charAt(0)&&o&&(n=o.slice(0,o.length-1),a=n.concat(a)),k=0;k0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}if((o||q)&&p){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),o)for(l=o.length;l>0;l-=1)if(e=p[o.slice(0,l).join("/")],e&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&q&&q[d]&&(i=q[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function g(b,c){return function(){var d=v.call(arguments,0);return"string"!=typeof d[0]&&1===d.length&&d.push(null),n.apply(a,d.concat([b,c]))}}function h(a){return function(b){return f(b,a)}}function i(a){return function(b){q[a]=b}}function j(b){if(e(r,b)){var c=r[b];delete r[b],t[b]=!0,m.apply(a,c)}if(!e(q,b)&&!e(t,b))throw new Error("No "+b);return q[b]}function k(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function l(a){return function(){return s&&s.config&&s.config[a]||{}}}var m,n,o,p,q={},r={},s={},t={},u=Object.prototype.hasOwnProperty,v=[].slice,w=/\.js$/;o=function(a,b){var c,d=k(a),e=d[0];return a=d[1],e&&(e=f(e,b),c=j(e)),e?a=c&&c.normalize?c.normalize(a,h(b)):f(a,b):(a=f(a,b),d=k(a),e=d[0],a=d[1],e&&(c=j(e))),{f:e?e+"!"+a:a,n:a,pr:e,p:c}},p={require:function(a){return g(a)},exports:function(a){var b=q[a];return"undefined"!=typeof b?b:q[a]={}},module:function(a){return{id:a,uri:"",exports:q[a],config:l(a)}}},m=function(b,c,d,f){var h,k,l,m,n,s,u=[],v=typeof d;if(f=f||b,"undefined"===v||"function"===v){for(c=!c.length&&d.length?["require","exports","module"]:c,n=0;nc;c++)if(m[c].matchRoute(a.pathname))return b(m[c]);return b()}function g(a){a.options.cache=!!a.options.cache,m.push(a)}function h(a){n=window.location.origin+a}function i(){c(),l.monitorBrowserNavigation()}var j=a("../utils/utils"),k=a("../http/http"),l=a("../history/history"),m=[],n="/";b.addRoute=g,b.addFallback=h,b.start=i}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("route/route.model",["require","exports"],a)}(function(a,b){"use strict";var c=function(){function a(a,b){this.cachedTemplate=null,this.path=a,this.options=b}return a.prototype.matchRoute=function(a){var b=a.split("/"),c=this.path.split("/");if("/"===a&&a===this.path)return!0;if(c.length!==b.length)return!1;for(var d=1,e=c.length;e>d;d++){var f=b[d]+"|\\:\\w+",g=new RegExp(f);if(!g.test(c[d]))return!1}return!0},a.prototype.getParams=function(a){for(var b=a.split("/"),c=this.path.split("/"),d={},e=1,f=c.length;f>e;e++){var g=/:\w+/;if(g.test(c[e])){var h=c[e].replace(":","");d[h]=b[e]}}return d},a.prototype.isCached=function(){return!!this.cachedTemplate},a.prototype.storeTemplateToCache=function(a){this.cachedTemplate=a},a.prototype.getCachedTemplate=function(){return this.cachedTemplate},a}();b.Route=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("route/route.provider",["require","exports","./route.model","./route.observer"],a)}(function(a,b){"use strict";var c=a("./route.model"),d=a("./route.observer"),e={when:function(a,b){var e=new c.Route(a,b);return d.addRoute(e),this},otherwise:function(a){return d.addFallback(a),this}};Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=e}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("router/router",["require","exports","./router.events","../route/route.observer","../route/route.provider","../utils/utils"],a)}(function(a,b){"use strict";var c=a("./router.events"),d=a("../route/route.observer"),e=a("../route/route.provider"),f=a("../utils/utils"),g=function(){function a(a,b){f.setRoot(a),f.setView(b)}return a.prototype.config=function(a){a(e["default"]),c.register(),d.start(),c.onRun()},a}();Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=g}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("index",["require","exports","./router/router"],a)}(function(a,b){"use strict";var c=a("./router/router");Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=c["default"]}),a.JSRoute=a.JSRoute||c("index")["default"]}(window); \ No newline at end of file +!function(a){var b,c,d;!function(a){function e(a,b){return u.call(a,b)}function f(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o=b&&b.split("/"),p=s.map,q=p&&p["*"]||{};if(a){for(a=a.split("/"),g=a.length-1,s.nodeIdCompat&&w.test(a[g])&&(a[g]=a[g].replace(w,"")),"."===a[0].charAt(0)&&o&&(n=o.slice(0,o.length-1),a=n.concat(a)),k=0;k0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}if((o||q)&&p){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),o)for(l=o.length;l>0;l-=1)if(e=p[o.slice(0,l).join("/")],e&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&q&&q[d]&&(i=q[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function g(b,c){return function(){var d=v.call(arguments,0);return"string"!=typeof d[0]&&1===d.length&&d.push(null),n.apply(a,d.concat([b,c]))}}function h(a){return function(b){return f(b,a)}}function i(a){return function(b){q[a]=b}}function j(b){if(e(r,b)){var c=r[b];delete r[b],t[b]=!0,m.apply(a,c)}if(!e(q,b)&&!e(t,b))throw new Error("No "+b);return q[b]}function k(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function l(a){return function(){return s&&s.config&&s.config[a]||{}}}var m,n,o,p,q={},r={},s={},t={},u=Object.prototype.hasOwnProperty,v=[].slice,w=/\.js$/;o=function(a,b){var c,d=k(a),e=d[0];return a=d[1],e&&(e=f(e,b),c=j(e)),e?a=c&&c.normalize?c.normalize(a,h(b)):f(a,b):(a=f(a,b),d=k(a),e=d[0],a=d[1],e&&(c=j(e))),{f:e?e+"!"+a:a,n:a,pr:e,p:c}},p={require:function(a){return g(a)},exports:function(a){var b=q[a];return"undefined"!=typeof b?b:q[a]={}},module:function(a){return{id:a,uri:"",exports:q[a],config:l(a)}}},m=function(b,c,d,f){var h,k,l,m,n,s,u=[],v=typeof d;if(f=f||b,"undefined"===v||"function"===v){for(c=!c.length&&d.length?["require","exports","module"]:c,n=0;nc;c++)if(m[c].matchRoute(a.pathname))return b(m[c]);return b()}function g(a){a.options.cache=!!a.options.cache,m.push(a)}function h(a){n=window.location.origin+a}function i(){c(),l.monitorBrowserNavigation()}var j=a("../utils/utils"),k=a("../http/http"),l=a("../history/history"),m=[],n="/";b.addRoute=g,b.addFallback=h,b.start=i}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("route/route.model",["require","exports"],a)}(function(a,b){"use strict";var c=function(){function a(a,b){this.cachedTemplate=null,this.path=a,this.options=b}return a.prototype.matchRoute=function(a){var b=a.split("/"),c=this.path.split("/");if("/"===a&&a===this.path)return!0;if(c.length!==b.length)return!1;for(var d=1,e=c.length;e>d;d++){var f=b[d]+"|\\:\\w+",g=new RegExp(f);if(!g.test(c[d]))return!1}return!0},a.prototype.getParams=function(a){for(var b=a.split("/"),c=this.path.split("/"),d={},e=1,f=c.length;f>e;e++){var g=/:\w+/;if(g.test(c[e])){var h=c[e].replace(":","");d[h]=b[e]}}return d},a.prototype.isCached=function(){return!!this.cachedTemplate},a.prototype.storeTemplateToCache=function(a){this.cachedTemplate=a},a.prototype.getCachedTemplate=function(){return this.cachedTemplate},a}();Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("route/route.provider",["require","exports","./route.model","./route.observer"],a)}(function(a,b){"use strict";var c=a("./route.model"),d=a("./route.observer"),e={when:function(a,b){var e=new c["default"](a,b);return d.addRoute(e),this},otherwise:function(a){return d.addFallback(a),this}};Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=e}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("router/router",["require","exports","./router.events","../route/route.observer","../route/route.provider","../utils/utils"],a)}(function(a,b){"use strict";var c=a("./router.events"),d=a("../route/route.observer"),e=a("../route/route.provider"),f=a("../utils/utils"),g=function(){function a(a,b){f.setRoot(a),f.setView(b)}return a.prototype.config=function(a){a(e["default"]),c.register(),d.start(),c.onRun()},a}();Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=g}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(c,exports);void 0!==b&&(module.exports=b)}else"function"==typeof d&&d.amd&&d("index",["require","exports","./router/router"],a)}(function(a,b){"use strict";var c=a("./router/router");Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=c["default"]}),a.JSRoute=a.JSRoute||c("index")["default"]}(window); \ No newline at end of file diff --git a/dist/jsRoute.noamd.js b/dist/jsRoute.noamd.js index d3c2045..8a13060 100644 --- a/dist/jsRoute.noamd.js +++ b/dist/jsRoute.noamd.js @@ -13,7 +13,8 @@ _event = new CustomEvent(eventName, eventData); element.dispatchEvent(_event); } - exports.broadcastEvent = broadcastEvent; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = broadcastEvent; }); //# sourceMappingURL=../../src/tmp/maps/events/eventHandler.js.map; (function (factory) { @@ -84,18 +85,18 @@ this.matchingPath = ''; } $Location.prototype.path = function (href) { - router_events_1.startRouteChange(constructRoute(href)); + router_events_1.startRouteChange(routeFactory(href)); }; return $Location; }()); - exports.$Location = $Location; - function constructRoute(url) { + function routeFactory(url) { var prev = window.location; var next = new $Location(url); var locationList = { next: next, prev: prev }; return locationList; } - exports.constructRoute = constructRoute; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = routeFactory; }); //# sourceMappingURL=../../src/tmp/maps/location/location.model.js.map; (function (factory) { @@ -107,17 +108,17 @@ } })(function (require, exports) { 'use strict'; - var eventHandler = require('../events/eventHandler'); + var eventHandler_1 = require('../events/eventHandler'); var location_model_1 = require('../location/location.model'); var utils = require('../utils/utils'); function onRun() { - startRouteChange(location_model_1.constructRoute(window.location.origin + window.location.pathname)); + startRouteChange(location_model_1.default(window.location.origin + window.location.pathname)); } exports.onRun = onRun; function startRouteChange(location) { var root = utils.getRoot(); var locationList = location; - eventHandler.broadcastEvent('routeChange', root, { detail: locationList }); + eventHandler_1.default('routeChange', root, { detail: locationList }); } exports.startRouteChange = startRouteChange; function interceptLinks() { @@ -125,7 +126,7 @@ root.addEventListener('click', function (ev) { if (ev.target.nodeName === 'A') { ev.preventDefault(); - startRouteChange(location_model_1.constructRoute(ev.target.href)); + startRouteChange(location_model_1.default(ev.target.href)); } }); } @@ -194,7 +195,7 @@ window.addEventListener('popstate', function (ev) { ev.preventDefault(); popStateInvoked = true; - router_events_1.startRouteChange(location_model_1.constructRoute(ev.state.path)); + router_events_1.startRouteChange(location_model_1.default(ev.state.path)); }); } exports.monitorBrowserNavigation = monitorBrowserNavigation; @@ -230,10 +231,8 @@ return callback(); } view.innerHTML = data; - if (route.options.cache) { - if (!isCached) { - route.storeTemplateToCache(data); - } + if (route.options.cache && !isCached) { + route.storeTemplateToCache(data); } return callback(null, true); }); @@ -352,7 +351,8 @@ }; return Route; }()); - exports.Route = Route; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = Route; }); //# sourceMappingURL=../../src/tmp/maps/route/route.model.js.map; (function (factory) { @@ -368,7 +368,7 @@ var observer = require('./route.observer'); var provider = { when: function (path, options) { - var route = new route_model_1.Route(path, options); + var route = new route_model_1.default(path, options); observer.addRoute(route); return this; }, diff --git a/dist/jsRoute.noamd.min.js b/dist/jsRoute.noamd.min.js index 30e9c7d..5dcdc30 100644 --- a/dist/jsRoute.noamd.min.js +++ b/dist/jsRoute.noamd.min.js @@ -1 +1 @@ -!function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("events/eventHandler",["require","exports"],a)}(function(a,b){"use strict";function c(a,b,c){var d;c.cancelable=!0,d=new CustomEvent(a,c),b.dispatchEvent(d)}b.broadcastEvent=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("utils/utils",["require","exports"],a)}(function(a,b){"use strict";function c(){}function d(a){a=a||".jsroute-view",l=document.querySelector(a)}function e(){return l}function f(a){a=a||".jsroute-app",k=document.querySelector(a)}function g(){return k}var h=/\w+\:\/\//;b.protocolRegex=h;var i=/\w+\.\w{1,4}\//;b.hostRegex=i;var j=/\/w+|d+$|\//;b.pathRegex=j;var k,l;b.noop=c,b.setView=d,b.getView=e,b.setRoot=f,b.getRoot=g}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("location/location.model",["require","exports","../utils/utils","../router/router.events"],a)}(function(a,b){"use strict";function c(a){var b=window.location,c=new f(a),d={next:c,prev:b};return d}var d=a("../utils/utils"),e=a("../router/router.events"),f=function(){function a(a){this.params={};var b=a.match(/^#*\?|$/),c=a.match(d.hostRegex),e=a.match(d.protocolRegex),f=a.match(/^\?*$/);this.hash=b?b[0]:"",this.host=c?c[0]:window.location.host,this.hostname=this.host.match(/\w+/)[0],this.protocol=e?e[0].replace("//",""):window.location.protocol,this.origin=this.protocol+"//"+this.host,this.pathname=a.replace(this.protocol+"//","").replace(this.host,""),this.search=f?f[0]:"",this.href=""+this.origin+this.pathname,this.matchingPath=""}return a.prototype.path=function(a){e.startRouteChange(c(a))},a}();b.$Location=f,b.constructRoute=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("router/router.events",["require","exports","../events/eventHandler","../location/location.model","../utils/utils"],a)}(function(a,b){"use strict";function c(){d(h.constructRoute(window.location.origin+window.location.pathname))}function d(a){var b=i.getRoot(),c=a;g.broadcastEvent("routeChange",b,{detail:c})}function e(){var a=i.getRoot();a.addEventListener("click",function(a){"A"===a.target.nodeName&&(a.preventDefault(),d(h.constructRoute(a.target.href)))})}function f(){e()}var g=a("../events/eventHandler"),h=a("../location/location.model"),i=a("../utils/utils");b.onRun=c,b.startRouteChange=d,b.register=f}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("http/http",["require","exports","../utils/utils"],a)}(function(a,b){"use strict";var c=a("../utils/utils"),d={get:function(a,b){function d(){f.readyState===XMLHttpRequest.DONE&&(200===f.status?e(null,f.responseText):e(f.status))}var e=b||c.noop,f=new XMLHttpRequest;f.onreadystatechange=d,f.open("GET",a),f.send()}};Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=d}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("history/history",["require","exports","../router/router.events","../location/location.model"],a)}(function(a,b){"use strict";function c(a,b){var c=a.options.templateUrl.split("/"),d=c.pop();h||g.pushState({path:b},d,b),h=!1}function d(){window.addEventListener("popstate",function(a){a.preventDefault(),h=!0,e.startRouteChange(f.constructRoute(a.state.path))})}var e=a("../router/router.events"),f=a("../location/location.model"),g=window.history,h=!1;b.push=c,b.monitorBrowserNavigation=d}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("route/route.observer",["require","exports","../utils/utils","../http/http","../history/history"],a)}(function(a,b){"use strict";function c(){var a=j.getRoot();a.addEventListener("routeChange",e,!1)}function d(a,b){var c=a.isCached(),d=j.getView();return c?(d.innerHTML=a.getCachedTemplate(),b(null,!0)):void k["default"].get(a.options.templateUrl,function(e,f){return e?b(e):f?(d.innerHTML=f,a.options.cache&&(c||a.storeTemplateToCache(f)),b(null,!0)):b()})}function e(a){if(!a.defaultPrevented){var b=a.detail.next,c=a.detail.prev;b.host!==c.host&&window.location.assign(b.href),f(b,function(a){return a?(l.push(a,b.pathname),b.matchingPath=a.path,b.params=a.getParams(b.pathname),void d(a,function(c,d){return c?console.error(c):d?void(a.options.onLoad&&a.options.onLoad(j.getRoot(),b)):console.error("No template retrieved from templateUrl")})):b.path(n)})}}function f(a,b){for(var c=0,d=m.length;d>c;c++)if(m[c].matchRoute(a.pathname))return b(m[c]);return b()}function g(a){a.options.cache=!!a.options.cache,m.push(a)}function h(a){n=window.location.origin+a}function i(){c(),l.monitorBrowserNavigation()}var j=a("../utils/utils"),k=a("../http/http"),l=a("../history/history"),m=[],n="/";b.addRoute=g,b.addFallback=h,b.start=i}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("route/route.model",["require","exports"],a)}(function(a,b){"use strict";var c=function(){function a(a,b){this.cachedTemplate=null,this.path=a,this.options=b}return a.prototype.matchRoute=function(a){var b=a.split("/"),c=this.path.split("/");if("/"===a&&a===this.path)return!0;if(c.length!==b.length)return!1;for(var d=1,e=c.length;e>d;d++){var f=b[d]+"|\\:\\w+",g=new RegExp(f);if(!g.test(c[d]))return!1}return!0},a.prototype.getParams=function(a){for(var b=a.split("/"),c=this.path.split("/"),d={},e=1,f=c.length;f>e;e++){var g=/:\w+/;if(g.test(c[e])){var h=c[e].replace(":","");d[h]=b[e]}}return d},a.prototype.isCached=function(){return!!this.cachedTemplate},a.prototype.storeTemplateToCache=function(a){this.cachedTemplate=a},a.prototype.getCachedTemplate=function(){return this.cachedTemplate},a}();b.Route=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("route/route.provider",["require","exports","./route.model","./route.observer"],a)}(function(a,b){"use strict";var c=a("./route.model"),d=a("./route.observer"),e={when:function(a,b){var e=new c.Route(a,b);return d.addRoute(e),this},otherwise:function(a){return d.addFallback(a),this}};Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=e}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("router/router",["require","exports","./router.events","../route/route.observer","../route/route.provider","../utils/utils"],a)}(function(a,b){"use strict";var c=a("./router.events"),d=a("../route/route.observer"),e=a("../route/route.provider"),f=a("../utils/utils"),g=function(){function a(a,b){f.setRoot(a),f.setView(b)}return a.prototype.config=function(a){a(e["default"]),c.register(),d.start(),c.onRun()},a}();Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=g}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("JSRoute",["require","exports","./router/router"],a)}(function(a,b){"use strict";var c=a("./router/router");Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=c["default"]}); \ No newline at end of file +!function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("events/eventHandler",["require","exports"],a)}(function(a,b){"use strict";function c(a,b,c){var d;c.cancelable=!0,d=new CustomEvent(a,c),b.dispatchEvent(d)}Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("utils/utils",["require","exports"],a)}(function(a,b){"use strict";function c(){}function d(a){a=a||".jsroute-view",l=document.querySelector(a)}function e(){return l}function f(a){a=a||".jsroute-app",k=document.querySelector(a)}function g(){return k}var h=/\w+\:\/\//;b.protocolRegex=h;var i=/\w+\.\w{1,4}\//;b.hostRegex=i;var j=/\/w+|d+$|\//;b.pathRegex=j;var k,l;b.noop=c,b.setView=d,b.getView=e,b.setRoot=f,b.getRoot=g}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("location/location.model",["require","exports","../utils/utils","../router/router.events"],a)}(function(a,b){"use strict";function c(a){var b=window.location,c=new f(a),d={next:c,prev:b};return d}var d=a("../utils/utils"),e=a("../router/router.events"),f=function(){function a(a){this.params={};var b=a.match(/^#*\?|$/),c=a.match(d.hostRegex),e=a.match(d.protocolRegex),f=a.match(/^\?*$/);this.hash=b?b[0]:"",this.host=c?c[0]:window.location.host,this.hostname=this.host.match(/\w+/)[0],this.protocol=e?e[0].replace("//",""):window.location.protocol,this.origin=this.protocol+"//"+this.host,this.pathname=a.replace(this.protocol+"//","").replace(this.host,""),this.search=f?f[0]:"",this.href=""+this.origin+this.pathname,this.matchingPath=""}return a.prototype.path=function(a){e.startRouteChange(c(a))},a}();Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("router/router.events",["require","exports","../events/eventHandler","../location/location.model","../utils/utils"],a)}(function(a,b){"use strict";function c(){d(h["default"](window.location.origin+window.location.pathname))}function d(a){var b=i.getRoot(),c=a;g["default"]("routeChange",b,{detail:c})}function e(){var a=i.getRoot();a.addEventListener("click",function(a){"A"===a.target.nodeName&&(a.preventDefault(),d(h["default"](a.target.href)))})}function f(){e()}var g=a("../events/eventHandler"),h=a("../location/location.model"),i=a("../utils/utils");b.onRun=c,b.startRouteChange=d,b.register=f}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("http/http",["require","exports","../utils/utils"],a)}(function(a,b){"use strict";var c=a("../utils/utils"),d={get:function(a,b){function d(){f.readyState===XMLHttpRequest.DONE&&(200===f.status?e(null,f.responseText):e(f.status))}var e=b||c.noop,f=new XMLHttpRequest;f.onreadystatechange=d,f.open("GET",a),f.send()}};Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=d}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("history/history",["require","exports","../router/router.events","../location/location.model"],a)}(function(a,b){"use strict";function c(a,b){var c=a.options.templateUrl.split("/"),d=c.pop();h||g.pushState({path:b},d,b),h=!1}function d(){window.addEventListener("popstate",function(a){a.preventDefault(),h=!0,e.startRouteChange(f["default"](a.state.path))})}var e=a("../router/router.events"),f=a("../location/location.model"),g=window.history,h=!1;b.push=c,b.monitorBrowserNavigation=d}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("route/route.observer",["require","exports","../utils/utils","../http/http","../history/history"],a)}(function(a,b){"use strict";function c(){var a=j.getRoot();a.addEventListener("routeChange",e,!1)}function d(a,b){var c=a.isCached(),d=j.getView();return c?(d.innerHTML=a.getCachedTemplate(),b(null,!0)):void k["default"].get(a.options.templateUrl,function(e,f){return e?b(e):f?(d.innerHTML=f,a.options.cache&&!c&&a.storeTemplateToCache(f),b(null,!0)):b()})}function e(a){if(!a.defaultPrevented){var b=a.detail.next,c=a.detail.prev;b.host!==c.host&&window.location.assign(b.href),f(b,function(a){return a?(l.push(a,b.pathname),b.matchingPath=a.path,b.params=a.getParams(b.pathname),void d(a,function(c,d){return c?console.error(c):d?void(a.options.onLoad&&a.options.onLoad(j.getRoot(),b)):console.error("No template retrieved from templateUrl")})):b.path(n)})}}function f(a,b){for(var c=0,d=m.length;d>c;c++)if(m[c].matchRoute(a.pathname))return b(m[c]);return b()}function g(a){a.options.cache=!!a.options.cache,m.push(a)}function h(a){n=window.location.origin+a}function i(){c(),l.monitorBrowserNavigation()}var j=a("../utils/utils"),k=a("../http/http"),l=a("../history/history"),m=[],n="/";b.addRoute=g,b.addFallback=h,b.start=i}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("route/route.model",["require","exports"],a)}(function(a,b){"use strict";var c=function(){function a(a,b){this.cachedTemplate=null,this.path=a,this.options=b}return a.prototype.matchRoute=function(a){var b=a.split("/"),c=this.path.split("/");if("/"===a&&a===this.path)return!0;if(c.length!==b.length)return!1;for(var d=1,e=c.length;e>d;d++){var f=b[d]+"|\\:\\w+",g=new RegExp(f);if(!g.test(c[d]))return!1}return!0},a.prototype.getParams=function(a){for(var b=a.split("/"),c=this.path.split("/"),d={},e=1,f=c.length;f>e;e++){var g=/:\w+/;if(g.test(c[e])){var h=c[e].replace(":","");d[h]=b[e]}}return d},a.prototype.isCached=function(){return!!this.cachedTemplate},a.prototype.storeTemplateToCache=function(a){this.cachedTemplate=a},a.prototype.getCachedTemplate=function(){return this.cachedTemplate},a}();Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=c}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("route/route.provider",["require","exports","./route.model","./route.observer"],a)}(function(a,b){"use strict";var c=a("./route.model"),d=a("./route.observer"),e={when:function(a,b){var e=new c["default"](a,b);return d.addRoute(e),this},otherwise:function(a){return d.addFallback(a),this}};Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=e}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("router/router",["require","exports","./router.events","../route/route.observer","../route/route.provider","../utils/utils"],a)}(function(a,b){"use strict";var c=a("./router.events"),d=a("../route/route.observer"),e=a("../route/route.provider"),f=a("../utils/utils"),g=function(){function a(a,b){f.setRoot(a),f.setView(b)}return a.prototype.config=function(a){a(e["default"]),c.register(),d.start(),c.onRun()},a}();Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=g}),function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);void 0!==b&&(module.exports=b)}else"function"==typeof define&&define.amd&&define("JSRoute",["require","exports","./router/router"],a)}(function(a,b){"use strict";var c=a("./router/router");Object.defineProperty(b,"__esModule",{value:!0}),b["default"]=c["default"]}); \ No newline at end of file diff --git a/example/jsRoute.js b/example/jsRoute.js index 4ffaf8d..d8ae30b 100644 --- a/example/jsRoute.js +++ b/example/jsRoute.js @@ -443,7 +443,8 @@ define("../node_modules/almond/almond", function(){}); _event = new CustomEvent(eventName, eventData); element.dispatchEvent(_event); } - exports.broadcastEvent = broadcastEvent; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = broadcastEvent; }); //# sourceMappingURL=../../src/tmp/maps/events/eventHandler.js.map; (function (factory) { @@ -514,18 +515,18 @@ define("../node_modules/almond/almond", function(){}); this.matchingPath = ''; } $Location.prototype.path = function (href) { - router_events_1.startRouteChange(constructRoute(href)); + router_events_1.startRouteChange(routeFactory(href)); }; return $Location; }()); - exports.$Location = $Location; - function constructRoute(url) { + function routeFactory(url) { var prev = window.location; var next = new $Location(url); var locationList = { next: next, prev: prev }; return locationList; } - exports.constructRoute = constructRoute; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = routeFactory; }); //# sourceMappingURL=../../src/tmp/maps/location/location.model.js.map; (function (factory) { @@ -537,17 +538,17 @@ define("../node_modules/almond/almond", function(){}); } })(function (require, exports) { 'use strict'; - var eventHandler = require('../events/eventHandler'); + var eventHandler_1 = require('../events/eventHandler'); var location_model_1 = require('../location/location.model'); var utils = require('../utils/utils'); function onRun() { - startRouteChange(location_model_1.constructRoute(window.location.origin + window.location.pathname)); + startRouteChange(location_model_1.default(window.location.origin + window.location.pathname)); } exports.onRun = onRun; function startRouteChange(location) { var root = utils.getRoot(); var locationList = location; - eventHandler.broadcastEvent('routeChange', root, { detail: locationList }); + eventHandler_1.default('routeChange', root, { detail: locationList }); } exports.startRouteChange = startRouteChange; function interceptLinks() { @@ -555,7 +556,7 @@ define("../node_modules/almond/almond", function(){}); root.addEventListener('click', function (ev) { if (ev.target.nodeName === 'A') { ev.preventDefault(); - startRouteChange(location_model_1.constructRoute(ev.target.href)); + startRouteChange(location_model_1.default(ev.target.href)); } }); } @@ -624,7 +625,7 @@ define("../node_modules/almond/almond", function(){}); window.addEventListener('popstate', function (ev) { ev.preventDefault(); popStateInvoked = true; - router_events_1.startRouteChange(location_model_1.constructRoute(ev.state.path)); + router_events_1.startRouteChange(location_model_1.default(ev.state.path)); }); } exports.monitorBrowserNavigation = monitorBrowserNavigation; @@ -660,10 +661,8 @@ define("../node_modules/almond/almond", function(){}); return callback(); } view.innerHTML = data; - if (route.options.cache) { - if (!isCached) { - route.storeTemplateToCache(data); - } + if (route.options.cache && !isCached) { + route.storeTemplateToCache(data); } return callback(null, true); }); @@ -782,7 +781,8 @@ define("../node_modules/almond/almond", function(){}); }; return Route; }()); - exports.Route = Route; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = Route; }); //# sourceMappingURL=../../src/tmp/maps/route/route.model.js.map; (function (factory) { @@ -798,7 +798,7 @@ define("../node_modules/almond/almond", function(){}); var observer = require('./route.observer'); var provider = { when: function (path, options) { - var route = new route_model_1.Route(path, options); + var route = new route_model_1.default(path, options); observer.addRoute(route); return this; }, diff --git a/src/events/eventHandler.ts b/src/events/eventHandler.ts index 049f473..e900acc 100644 --- a/src/events/eventHandler.ts +++ b/src/events/eventHandler.ts @@ -10,4 +10,4 @@ function broadcastEvent(eventName: string, element, eventData): void { element.dispatchEvent(_event); } -export { broadcastEvent }; +export default broadcastEvent; diff --git a/src/history/history.ts b/src/history/history.ts index 6e75164..883185a 100644 --- a/src/history/history.ts +++ b/src/history/history.ts @@ -1,7 +1,7 @@ 'use strict'; import { startRouteChange } from '../router/router.events'; -import { constructRoute } from '../location/location.model'; +import routeFactory from '../location/location.model'; var $history = window.history; var popStateInvoked = false; @@ -21,7 +21,7 @@ function monitorBrowserNavigation() { window.addEventListener('popstate', (ev) => { ev.preventDefault(); popStateInvoked = true; - startRouteChange(constructRoute(ev.state.path)); + startRouteChange(routeFactory(ev.state.path)); }); } diff --git a/src/location/location.model.ts b/src/location/location.model.ts index 70a4cf8..7cbdf92 100644 --- a/src/location/location.model.ts +++ b/src/location/location.model.ts @@ -35,11 +35,11 @@ class $Location { } public path(href: string): void { - startRouteChange(constructRoute(href)); + startRouteChange(routeFactory(href)); } } -function constructRoute(url: string): LocationInterface.LocationList { +function routeFactory(url: string): LocationInterface.LocationList { var prev: Location = window.location; var next: LocationInterface.NewLocation = new $Location(url); var locationList: LocationInterface.LocationList = { next, prev }; @@ -47,5 +47,4 @@ function constructRoute(url: string): LocationInterface.LocationList { return locationList; } -export { constructRoute }; -export { $Location }; +export default routeFactory; diff --git a/src/route/route.model.ts b/src/route/route.model.ts index ed3437c..281a3a7 100644 --- a/src/route/route.model.ts +++ b/src/route/route.model.ts @@ -59,4 +59,4 @@ class Route { } } -export { Route }; +export default Route; diff --git a/src/route/route.observer.ts b/src/route/route.observer.ts index fb83083..bb09683 100644 --- a/src/route/route.observer.ts +++ b/src/route/route.observer.ts @@ -1,11 +1,11 @@ 'use strict'; -import * as routeModel from './route.model'; +import Route from './route.model'; import * as utils from '../utils/utils'; import $http from '../http/http'; import * as $history from '../history/history'; -var routes: Array = []; +var routes: Array = []; var fallback = '/'; function monitorRouteChange(): void { @@ -14,7 +14,7 @@ function monitorRouteChange(): void { root.addEventListener('routeChange', changeCallback, false); } -function insertTemplate(route: routeModel.Route, callback): void { +function insertTemplate(route: Route, callback): void { const isCached = route.isCached(); var view = utils.getView(); diff --git a/src/route/route.provider.ts b/src/route/route.provider.ts index e8ec0cb..31072c0 100644 --- a/src/route/route.provider.ts +++ b/src/route/route.provider.ts @@ -2,7 +2,7 @@ import RouteInterface from '../typings/route/route.d'; -import { Route } from './route.model'; +import Route from './route.model'; import * as observer from './route.observer'; var provider: RouteInterface.RouteProvider = { diff --git a/src/router/router.events.ts b/src/router/router.events.ts index cd3dd71..feeac31 100644 --- a/src/router/router.events.ts +++ b/src/router/router.events.ts @@ -2,20 +2,20 @@ import LocationInterface from '../typings/location/location.d'; -import * as eventHandler from '../events/eventHandler'; -import { constructRoute } from '../location/location.model'; +import broadcastEvent from '../events/eventHandler'; +import routeFactory from '../location/location.model'; import * as utils from '../utils/utils'; function onRun() { // Determine current route and load the template based on it - startRouteChange(constructRoute(window.location.origin + window.location.pathname)); + startRouteChange(routeFactory(window.location.origin + window.location.pathname)); } function startRouteChange(location) { var root = utils.getRoot(); var locationList: LocationInterface.LocationList = location; - eventHandler.broadcastEvent('routeChange', root, { detail: locationList }); + broadcastEvent('routeChange', root, { detail: locationList }); } function interceptLinks() { @@ -25,7 +25,7 @@ function interceptLinks() { if (ev.target.nodeName === 'A') { ev.preventDefault(); // Start route matching and change - startRouteChange(constructRoute(ev.target.href)); + startRouteChange(routeFactory(ev.target.href)); } }); }