riot-route
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -12,28 +12,28 @@ 'use strict'; | ||
const RE_ORIGIN = /^.+?\/\/+[^\/]+/; | ||
const EVENT_LISTENER = 'EventListener'; | ||
const REMOVE_EVENT_LISTENER = 'remove' + EVENT_LISTENER; | ||
const ADD_EVENT_LISTENER = 'add' + EVENT_LISTENER; | ||
const HAS_ATTRIBUTE = 'hasAttribute'; | ||
const POPSTATE = 'popstate'; | ||
const HASHCHANGE = 'hashchange'; | ||
const TRIGGER = 'trigger'; | ||
const MAX_EMIT_STACK_LEVEL = 3; | ||
const win = typeof window != 'undefined' && window; | ||
const doc = typeof document != 'undefined' && document; | ||
const hist = win && history; | ||
const loc = win && (hist.location || win.location); | ||
const prot = Router.prototype; | ||
const clickEvent = doc && doc.ontouchstart ? 'touchstart' : 'click'; | ||
const central = observable(); | ||
var RE_ORIGIN = /^.+?\/\/+[^\/]+/; | ||
var EVENT_LISTENER = 'EventListener'; | ||
var REMOVE_EVENT_LISTENER = 'remove' + EVENT_LISTENER; | ||
var ADD_EVENT_LISTENER = 'add' + EVENT_LISTENER; | ||
var HAS_ATTRIBUTE = 'hasAttribute'; | ||
var POPSTATE = 'popstate'; | ||
var HASHCHANGE = 'hashchange'; | ||
var TRIGGER = 'trigger'; | ||
var MAX_EMIT_STACK_LEVEL = 3; | ||
var win = typeof window != 'undefined' && window; | ||
var doc = typeof document != 'undefined' && document; | ||
var hist = win && history; | ||
var loc = win && (hist.location || win.location); | ||
var prot = Router.prototype; | ||
var clickEvent = doc && doc.ontouchstart ? 'touchstart' : 'click'; | ||
var central = observable(); | ||
let started = false; | ||
let routeFound = false; | ||
let debouncedEmit; | ||
let base; | ||
let current; | ||
let parser; | ||
let secondParser; | ||
let emitStack = []; | ||
let emitStackLevel = 0; | ||
var started = false; | ||
var routeFound = false; | ||
var debouncedEmit; | ||
var base; | ||
var current; | ||
var parser; | ||
var secondParser; | ||
var emitStack = []; | ||
var emitStackLevel = 0; | ||
@@ -56,10 +56,10 @@ /** | ||
function DEFAULT_SECOND_PARSER(path, filter) { | ||
const f = filter | ||
var f = filter | ||
.replace(/\?/g, '\\?') | ||
.replace(/\*/g, '([^/?#]+?)') | ||
.replace(/\.\./, '.*'); | ||
const re = new RegExp(`^${f}$`); | ||
const args = path.match(re); | ||
var re = new RegExp(("^" + f + "$")); | ||
var args = path.match(re); | ||
if (args) return args.slice(1) | ||
if (args) { return args.slice(1) } | ||
} | ||
@@ -74,3 +74,3 @@ | ||
function debounce(fn, delay) { | ||
let t; | ||
var t; | ||
return function () { | ||
@@ -91,3 +91,3 @@ clearTimeout(t); | ||
doc[ADD_EVENT_LISTENER](clickEvent, click); | ||
if (autoExec) emit(true); | ||
if (autoExec) { emit(true); } | ||
} | ||
@@ -135,8 +135,8 @@ | ||
// the stack is needed for redirections | ||
const isRoot = emitStackLevel === 0; | ||
if (MAX_EMIT_STACK_LEVEL <= emitStackLevel) return | ||
var isRoot = emitStackLevel === 0; | ||
if (MAX_EMIT_STACK_LEVEL <= emitStackLevel) { return } | ||
emitStackLevel++; | ||
emitStack.push(function() { | ||
const path = getPathFromBase(); | ||
var path = getPathFromBase(); | ||
if (force || path !== current) { | ||
@@ -148,4 +148,4 @@ central[TRIGGER]('emit', path); | ||
if (isRoot) { | ||
let first; | ||
while (first = emitStack.shift()) first(); // stack increses within this call | ||
var first; | ||
while (first = emitStack.shift()) { first(); } // stack increses within this call | ||
emitStackLevel = 0; | ||
@@ -160,6 +160,6 @@ } | ||
|| e.defaultPrevented // or default prevented | ||
) return | ||
) { return } | ||
let el = e.target; | ||
while (el && el.nodeName !== 'A') el = el.parentNode; | ||
var el = e.target; | ||
while (el && el.nodeName !== 'A') { el = el.parentNode; } | ||
@@ -172,3 +172,3 @@ if ( | ||
|| el.href.indexOf(loc.href.match(RE_ORIGIN)[0]) === -1 // cross origin | ||
) return | ||
) { return } | ||
@@ -181,3 +181,3 @@ if (el.href !== loc.href | ||
|| !go(getPathFromBase(el.href), el.title || doc.title) // route not found | ||
)) return | ||
)) { return } | ||
@@ -196,3 +196,3 @@ e.preventDefault(); | ||
// Server-side usage: directly execute handlers for the path | ||
if (!hist) return central[TRIGGER]('emit', getPathFromBase(path)) | ||
if (!hist) { return central[TRIGGER]('emit', getPathFromBase(path)) } | ||
@@ -224,5 +224,5 @@ path = base + normalize(path); | ||
prot.m = function(first, second, third) { | ||
if (isString(first) && (!second || isString(second))) go(first, second, third || false); | ||
else if (second) this.r(first, second); | ||
else this.r('@', first); | ||
if (isString(first) && (!second || isString(second))) { go(first, second, third || false); } | ||
else if (second) { this.r(first, second); } | ||
else { this.r('@', first); } | ||
}; | ||
@@ -244,3 +244,3 @@ | ||
this.$.concat('@').some(function(filter) { | ||
const args = (filter === '@' ? parser : secondParser)(normalize(path), normalize(filter)); | ||
var args = (filter === '@' ? parser : secondParser)(normalize(path), normalize(filter)); | ||
if (typeof args != 'undefined') { | ||
@@ -266,4 +266,4 @@ this[TRIGGER].apply(null, [filter].concat(args)); | ||
const mainRouter = new Router(); | ||
const route = mainRouter.m.bind(mainRouter); | ||
var mainRouter = new Router(); | ||
var route = mainRouter.m.bind(mainRouter); | ||
@@ -275,5 +275,5 @@ /** | ||
route.create = function() { | ||
const newSubRouter = new Router(); | ||
var newSubRouter = new Router(); | ||
// assign sub-router's main method | ||
const router = newSubRouter.m.bind(newSubRouter); | ||
var router = newSubRouter.m.bind(newSubRouter); | ||
// stop only this sub-router | ||
@@ -309,4 +309,4 @@ router.stop = newSubRouter.s.bind(newSubRouter); | ||
} | ||
if (fn) parser = fn; | ||
if (fn2) secondParser = fn2; | ||
if (fn) { parser = fn; } | ||
if (fn2) { secondParser = fn2; } | ||
}; | ||
@@ -319,4 +319,4 @@ | ||
route.query = function() { | ||
const q = {}; | ||
const href = loc.href || current; | ||
var q = {}; | ||
var href = loc.href || current; | ||
href.replace(/[?&](.+?)=([^&]*)/g, function(_, k, v) { q[k] = v; }); | ||
@@ -346,8 +346,8 @@ return q | ||
if (win) { | ||
if (document.readyState === 'complete') start(autoExec); | ||
if (document.readyState === 'complete') { start(autoExec); } | ||
// the timeout is needed to solve | ||
// a weird safari bug https://github.com/riot/route/issues/33 | ||
else win[ADD_EVENT_LISTENER]('load', function() { | ||
else { win[ADD_EVENT_LISTENER]('load', function() { | ||
setTimeout(function() { start(autoExec); }, 1); | ||
}); | ||
}); } | ||
} | ||
@@ -354,0 +354,0 @@ started = true; |
{ | ||
"name": "riot-route", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Simple isomorphic router", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs.route.js", |
@@ -22,3 +22,4 @@ const | ||
entry: 'lib/index.js', | ||
external: ['riot-observable'] | ||
external: ['riot-observable'], | ||
plugins: [buble()] | ||
}) | ||
@@ -25,0 +26,0 @@ .then(bundle => { |
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
87445
2138