Skip to content

Commit

Permalink
Add support for history version 5
Browse files Browse the repository at this point in the history
Closes #12
Closes #13
  • Loading branch information
dcsaszar committed Oct 20, 2020
1 parent 9224622 commit 3a74626
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 49 deletions.
48 changes: 5 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"devDependencies": {
"@types/history": "^4.7.8",
"@types/jasmine": "^3.5.14",
"history": "^4.10.1",
"history": "^5.0.0",
"jasmine-core": "^3.6.0",
"karma": "^5.2.3",
"karma-chrome-launcher": "^3.1.0",
Expand Down Expand Up @@ -33,12 +33,14 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"name": "scroll-to-fragment",
"peerDependencies": {},
"peerDependencies": {
"history": "4 || 5"
},
"repository": "github:Scrivito/scroll-to-fragment",
"scripts": {
"prepare": "rm -rf dist/* && npm test && tsc --build",
"test": "karma start --single-run",
"watch": "karma start"
},
"version": "1.0.8"
"version": "1.0.9"
}
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ function removeStopListener(eventName: string) {
document.removeEventListener(eventName, stopObserving);
}

function handleHistoryPush(update: History.Update): void; // history version 5
function handleHistoryPush(
_location: History.Location,
location: History.Location,
action: History.Action
): void; // history version 4
function handleHistoryPush(
update: History.Update & History.Location,
action?: History.Action
) {
if (action === "PUSH") startObserving();
if ("PUSH" === (action || update.action)) startObserving();
}

function handleDocumentClick(event: Event) {
Expand Down Expand Up @@ -107,7 +112,7 @@ function throttle(callback: () => void) {
}

let currentOptions: Readonly<Options>;
let unlistenHistory: History.UnregisterCallback | undefined;
let unlistenHistory: () => void | undefined;
let documentObserver: MutationObserver | undefined;
let observeTimeout: number | undefined;
let throttleRequestId: number | undefined;
Expand Down

0 comments on commit 3a74626

Please sign in to comment.