history-manager
Advanced tools
Comparing version 1.5.2 to 2.0.0
{ | ||
"name": "history-manager", | ||
"version": "1.5.2", | ||
"version": "2.0.0", | ||
"description": "", | ||
@@ -10,7 +10,7 @@ "dependencies": { | ||
"devDependencies": { | ||
"@riotjs/compiler": "^5.4.2", | ||
"@rollup/plugin-commonjs": "^19.0.0", | ||
"@rollup/plugin-node-resolve": "^13.0.0", | ||
"@rollup/plugin-typescript": "^8.2.1", | ||
"rollup": "^2.53.0", | ||
"@riotjs/compiler": "^6.0.1", | ||
"@rollup/plugin-commonjs": "^19.0.1", | ||
"@rollup/plugin-node-resolve": "^13.0.2", | ||
"@rollup/plugin-typescript": "^8.2.3", | ||
"rollup": "^2.53.3", | ||
"tslib": "^2.3.0", | ||
@@ -17,0 +17,0 @@ "typescript": "^4.3.5" |
@@ -67,2 +67,3 @@ import * as PathGenerator from "./PathGenerator"; | ||
insert(href: string, replace: boolean = false): void { | ||
href = PathGenerator.prepare(href); | ||
this.clean(); | ||
@@ -249,3 +250,3 @@ // console.group(`ContextManager.insert("${href}", ${replace})`); | ||
} | ||
context[1] = href; | ||
context[1] = href !== null ? PathGenerator.prepare(href) : null; | ||
} | ||
@@ -252,0 +253,0 @@ setContext(context: { |
@@ -103,14 +103,29 @@ /** | ||
let catchPopState: (() => void) | null = null; | ||
window.addEventListener("popstate", event => { | ||
if (!started || isLocked()) { | ||
return; | ||
let destroyEventListener: (() => void) | null = null; | ||
export function initEventListener() { | ||
if (destroyEventListener !== null) { | ||
return destroyEventListener; | ||
} | ||
if (catchPopState == null) { | ||
handlePopState(); | ||
return; | ||
} | ||
event.stopImmediatePropagation(); | ||
catchPopState(); | ||
}, true); | ||
const destroyOptionsEventListener = OptionsManager.initEventListener(); | ||
const listener = event => { | ||
if (!started || isLocked()) { | ||
return; | ||
} | ||
if (catchPopState == null) { | ||
handlePopState(); | ||
return; | ||
} | ||
event.stopImmediatePropagation(); | ||
catchPopState(); | ||
}; | ||
window.addEventListener("popstate", listener, true); | ||
return destroyEventListener = () => { | ||
window.removeEventListener("popstate", listener, true); | ||
destroyOptionsEventListener(); | ||
destroyEventListener = null; | ||
}; | ||
} | ||
function onCatchPopState(onCatchPopState: () => void, once: boolean = false): void { | ||
@@ -117,0 +132,0 @@ if (once) { |
@@ -25,10 +25,22 @@ /** | ||
let catchPopState: null | (() => void) = null; | ||
window.addEventListener("popstate", event => { | ||
if (catchPopState == null) { | ||
return handlePopState(); | ||
let destroyEventListener: (() => void) | null = null; | ||
export function initEventListener() { | ||
if (destroyEventListener !== null) { | ||
return destroyEventListener; | ||
} | ||
event.stopImmediatePropagation(); | ||
catchPopState(); | ||
}, true); | ||
const listener = event => { | ||
if (catchPopState == null) { | ||
return handlePopState(); | ||
} | ||
event.stopImmediatePropagation(); | ||
catchPopState(); | ||
}; | ||
window.addEventListener("popstate", listener, true); | ||
return destroyEventListener = () => { | ||
window.removeEventListener("popstate", listener, true); | ||
destroyEventListener = null; | ||
}; | ||
} | ||
function onCatchPopState(onCatchPopState: () => void, once: boolean = false): void { | ||
@@ -35,0 +47,0 @@ if (once) { |
@@ -11,11 +11,23 @@ /** | ||
let catchPopState: (() => void) | null = null; | ||
window.addEventListener("popstate", function (event: PopStateEvent): void { | ||
if (catchPopState == null) { | ||
return; | ||
let destroyEventListener: (() => void) | null = null; | ||
export function initEventListener() { | ||
if (destroyEventListener !== null) { | ||
return destroyEventListener; | ||
} | ||
event.stopImmediatePropagation(); | ||
event.stopPropagation(); | ||
catchPopState(); | ||
}, true); | ||
const listener = event => { | ||
if (catchPopState == null) { | ||
return; | ||
} | ||
event.stopImmediatePropagation(); | ||
event.stopPropagation(); | ||
catchPopState(); | ||
}; | ||
window.addEventListener("popstate", listener, true); | ||
return destroyEventListener = () => { | ||
window.removeEventListener("popstate", listener, true); | ||
destroyEventListener = null; | ||
}; | ||
} | ||
function onCatchPopState(onCatchPopState: () => void, once: boolean = false): void { | ||
@@ -22,0 +34,0 @@ if (once) { |
@@ -7,8 +7,8 @@ /** | ||
const LEADING_DELIMITER: RegExp = /^[\\\/]+/; | ||
const TRAILING_DELIMITER: RegExp = /[\\\/]+$/; | ||
const DELIMITER_NOT_IN_PARENTHESES: RegExp = /[\\\/]+(?![^(]*[)])/g; | ||
export const LEADING_DELIMITER: RegExp = /^[\\\/]+/; | ||
export const TRAILING_DELIMITER: RegExp = /[\\\/]+$/; | ||
export const DELIMITER_NOT_IN_PARENTHESES: RegExp = /[\\\/]+(?![^(]*[)])/g; | ||
export function prepare(path: string): string { | ||
return path.replace(LEADING_DELIMITER, "").replace(TRAILING_DELIMITER, "").replace(DELIMITER_NOT_IN_PARENTHESES, "/"); | ||
return ("/" + path).replace(TRAILING_DELIMITER, "").replace(DELIMITER_NOT_IN_PARENTHESES, "/"); | ||
} | ||
@@ -15,0 +15,0 @@ export function generate(path: Path, keys?: Key[]): RegExp { |
@@ -262,4 +262,20 @@ /** | ||
} | ||
window.addEventListener("historylanded", onland); | ||
let destroyEventListener: (() => void) | null = null; | ||
export function initEventListener() { | ||
if (destroyEventListener !== null) { | ||
return destroyEventListener; | ||
} | ||
const destroyHistoryEventListener = HistoryManager.initEventListener(); | ||
const destroyNavigationLockEventListener = NavigationLock.initEventListener(); | ||
window.addEventListener("historylanded", onland); | ||
return destroyEventListener = () => { | ||
window.removeEventListener("historylanded", onland); | ||
destroyNavigationLockEventListener(); | ||
destroyHistoryEventListener(); | ||
destroyEventListener = null; | ||
}; | ||
} | ||
function _go(path: string, replace: boolean = false, emit: boolean = true): Promise<void | undefined> { | ||
@@ -441,2 +457,3 @@ let lastEmitRoute: boolean = emitRoute; | ||
export function start (startingContext: string): Promise<void> { | ||
initEventListener(); | ||
return HistoryManager.start(startingContext); | ||
@@ -443,0 +460,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
242072
7037