@jack-henry/web-component-router
Advanced tools
Comparing version 3.3.0 to 3.4.0
@@ -16,2 +16,6 @@ /** The page instance */ | ||
_hashbang: boolean; | ||
_popstate: boolean; | ||
_click: boolean; | ||
/** @type {!Window|undefined} */ | ||
_window: Window | undefined; | ||
/** | ||
@@ -23,6 +27,2 @@ * Handle "click" events. | ||
_onpopstate: any; | ||
/** @type {!Window|undefined} */ | ||
_window: Window | undefined; | ||
_popstate: boolean; | ||
_click: boolean; | ||
/** | ||
@@ -61,4 +61,5 @@ * Configure the instance of page. This can be called multiple times. | ||
* @param {PageOptions=} options | ||
* @return {!Promise<undefined>} | ||
*/ | ||
start(options?: PageOptions | undefined): void; | ||
start(options?: PageOptions | undefined): Promise<undefined>; | ||
/** Unbind click and popstate event handlers. */ | ||
@@ -99,5 +100,5 @@ stop(): void; | ||
* @param {boolean=} dispatch | ||
* @return {!Context} | ||
* @return {!Promise<!Context>} | ||
*/ | ||
replace(path: string | undefined, state?: any | undefined, init?: boolean | undefined, dispatch?: boolean | undefined): Context; | ||
replace(path: string | undefined, state?: any | undefined, init?: boolean | undefined, dispatch?: boolean | undefined): Promise<Context>; | ||
/** | ||
@@ -199,2 +200,3 @@ * Dispatch the given `ctx`. | ||
pushState(): void; | ||
replaceState(): void; | ||
/** Save the context state. */ | ||
@@ -201,0 +203,0 @@ save(): void; |
@@ -73,2 +73,7 @@ /** | ||
this._hashbang = false; | ||
this._decodeURLComponents = true; | ||
this._popstate = true; | ||
this._click = true; | ||
/** @type {!Window|undefined} */ | ||
this._window = (hasWindow ? window : undefined); | ||
@@ -78,9 +83,2 @@ // bound functions | ||
this._onpopstate = this._onpopstate.bind(this); | ||
/** @type {!Window|undefined} */ | ||
this._window = (hasWindow ? window : undefined); | ||
this._decodeURLComponents = true; | ||
this._popstate = true; | ||
this._click = true; | ||
this._hashbang = false; | ||
} | ||
@@ -175,4 +173,5 @@ | ||
* @param {PageOptions=} options | ||
* @return {!Promise<undefined>} | ||
*/ | ||
start(options) { | ||
async start(options) { | ||
const opts = options || /** @type {!PageOptions} */ ({}); | ||
@@ -200,3 +199,3 @@ this.configure(opts); | ||
this.replace(url, null, true, opts.dispatch); | ||
await this.replace(url, null, true, opts.dispatch); | ||
} | ||
@@ -299,5 +298,5 @@ | ||
* @param {boolean=} dispatch | ||
* @return {!Context} | ||
* @return {!Promise<!Context>} | ||
*/ | ||
replace(path, state, init, dispatch) { | ||
async replace(path, state, init, dispatch) { | ||
const ctx = new Context(path, state, this); | ||
@@ -310,3 +309,3 @@ const prev = this.prevContext; | ||
if (false !== dispatch) { | ||
this.dispatch(ctx, prev); | ||
await this.dispatch(ctx, prev); | ||
} | ||
@@ -438,3 +437,3 @@ return ctx; | ||
path = path[0] !== '/' ? '/' + path : path; | ||
path = path[0] !== '/' ? `/${path}` : path; | ||
@@ -668,3 +667,3 @@ // strip leading "/[drive letter]:" on NW.js on Windows | ||
this.canonicalPath = path; | ||
const re = new RegExp('^' + escapeRegExp(pageBase)); | ||
const re = new RegExp(`^${escapeRegExp(pageBase)}`); | ||
this.path = path.replace(re, '') || '/'; | ||
@@ -738,2 +737,6 @@ if (hashbang) { | ||
replaceState() { | ||
return this.save(); | ||
} | ||
/** Save the context state. */ | ||
@@ -740,0 +743,0 @@ save() { |
@@ -285,18 +285,11 @@ /** | ||
let exitIndex = 0; | ||
let entryIndex = 0; | ||
async function nextExit() { | ||
const currentExitNode = exitNodes[exitIndex++]; | ||
const nextExitNode = exitNodes[exitIndex]; | ||
if (!currentExitNode) { | ||
exitNodes.forEach((node) => { | ||
const value = node.getValue(); | ||
if (value) { | ||
value.element = undefined; | ||
} | ||
}); | ||
return nextEntry(); | ||
} else if (currentExitNode.getValue().element) { | ||
const routingElem = /** @type {!BasicRoutingInterface} */ (currentExitNode.getValue().element); | ||
// Exit nodes | ||
for (let exitIndex = 0; exitIndex < exitNodes.length; exitIndex++) { | ||
const currentExitNode = exitNodes[exitIndex]; | ||
const nextExitNode = exitNodes[exitIndex + 1]; | ||
const value = currentExitNode.getValue(); | ||
if (value) { | ||
const routingElem = /** @type {!BasicRoutingInterface} */ ( | ||
/** @type {?} */ (currentExitNode.getValue().element) | ||
); | ||
if (!routingElem.routeExit) { | ||
@@ -306,19 +299,12 @@ throw new Error(`Element '${currentExitNode.getValue().tagName}' does not implement routeExit`); | ||
await routingElem.routeExit(currentExitNode, nextExitNode, routeId, context); | ||
return nextExit(); | ||
} else { | ||
return nextExit(); | ||
value.element = undefined; | ||
} | ||
} | ||
/** @param {(boolean|void)=} isNotCancelled */ | ||
async function nextEntry(isNotCancelled) { | ||
if (isNotCancelled === false) { | ||
return; | ||
} | ||
// entry nodes | ||
for (let entryIndex = 0; entryIndex < entryNodes.length; entryIndex++) { | ||
const currentEntryNode = entryNodes[entryIndex]; | ||
const nextEntryNode = entryNodes[entryIndex + 1]; | ||
const currentEntryNode = entryNodes[entryIndex++]; | ||
const nextEntryNode = entryNodes[entryIndex]; | ||
if (!currentEntryNode) { | ||
return; | ||
} else if (currentEntryNode.getValue().element) { | ||
if (currentEntryNode.getValue().element) { | ||
const routingElem = /** @type {!BasicRoutingInterface} */ ( | ||
@@ -331,9 +317,7 @@ /** @type {?} */ (currentEntryNode.getValue().element) | ||
const shouldContinue = await routingElem.routeEnter(currentEntryNode, nextEntryNode, routeId, context); | ||
return nextEntry(shouldContinue); | ||
} else { | ||
return nextEntry(); | ||
if (shouldContinue === false) { | ||
break; | ||
} | ||
} | ||
} | ||
await nextExit(); | ||
} | ||
@@ -340,0 +324,0 @@ } |
{ | ||
"name": "@jack-henry/web-component-router", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Web Components Router", | ||
@@ -45,11 +45,11 @@ "main": "router.js", | ||
"karma": "^6.x", | ||
"lit": "^3.1.3", | ||
"karma-chrome-launcher": "^3.2.0", | ||
"karma-jasmine": "5.x", | ||
"karma-spec-reporter": "^0.0.36", | ||
"lit": "^3.1.3", | ||
"typescript": "^5.2.2" | ||
}, | ||
"peerDependencies": { | ||
"lit":"^3.1.3" | ||
"lit": "^3.1.3" | ||
} | ||
} |
@@ -37,5 +37,5 @@ export default Router; | ||
* Build the routing tree and begin routing | ||
* @return {void} | ||
* @return {!Promise<undefined>} | ||
*/ | ||
start(): void; | ||
start(): Promise<undefined>; | ||
/** | ||
@@ -53,4 +53,5 @@ * Navigate to the specified route | ||
* NOTE: You must quote the properties so that Closure Compiler does not rename them! | ||
* @return {!Promise<!Context>} | ||
*/ | ||
redirect(path: string, params?: any | undefined): void; | ||
redirect(path: string, params?: any | undefined): Promise<Context>; | ||
/** | ||
@@ -57,0 +58,0 @@ * Return the path for the specified route |
@@ -98,5 +98,5 @@ /** | ||
* Build the routing tree and begin routing | ||
* @return {void} | ||
* @return {!Promise<undefined>} | ||
*/ | ||
start() { | ||
async start() { | ||
this.registerRoutes_(); | ||
@@ -107,3 +107,3 @@ | ||
this.page.start({ | ||
return this.page.start({ | ||
click: false, | ||
@@ -134,6 +134,7 @@ popstate: true, | ||
* NOTE: You must quote the properties so that Closure Compiler does not rename them! | ||
* @return {!Promise<!Context>} | ||
*/ | ||
redirect(path, params) { | ||
async redirect(path, params) { | ||
path = this.url(path, params); | ||
this.page.replace(path); | ||
return this.page.replace(path); | ||
} | ||
@@ -140,0 +141,0 @@ |
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
127300
2875