@stackflow/plugin-history-sync
Advanced tools
Comparing version 1.3.15 to 1.3.16
/// <reference types="react" /> | ||
export declare type HistoryQueueContextValue = { | ||
requestHistoryTick: (action: () => void, listen?: boolean) => void; | ||
requestHistoryTick: (cb: (resolve: () => void) => void) => void; | ||
}; | ||
@@ -5,0 +5,0 @@ export declare const HistoryQueueContext: import("react").Context<HistoryQueueContextValue>; |
@@ -207,15 +207,13 @@ "use strict"; | ||
let previousTask = Promise.resolve(); | ||
const requestHistoryTick = (cb, listen = true) => { | ||
const requestHistoryTick = (cb) => { | ||
previousTask = previousTask.then( | ||
() => new Promise((resolve) => { | ||
if (listen) { | ||
const clean = history.listen(() => { | ||
clean(); | ||
resolve(); | ||
}); | ||
} | ||
cb(); | ||
if (!listen) { | ||
const clean = history.listen(() => { | ||
clean(); | ||
resolve(); | ||
} | ||
}); | ||
cb(() => { | ||
clean(); | ||
resolve(); | ||
}); | ||
}) | ||
@@ -554,10 +552,16 @@ ); | ||
if (previousActivity) { | ||
do { | ||
for (let i = 0; i < previousActivity.steps.length - 1; i += 1) { | ||
requestHistoryTick(() => { | ||
for (let i = 0; i < previousActivity.steps.length - 1; i += 1) { | ||
requestHistoryTick((resolve) => { | ||
if (!safeParseState(getCurrentState({ history }))) { | ||
silentFlag = true; | ||
history.back(); | ||
}); | ||
} | ||
} while (!safeParseState(getCurrentState({ history }))); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
requestHistoryTick(() => { | ||
silentFlag = true; | ||
history.back(); | ||
}); | ||
} | ||
} | ||
@@ -586,10 +590,16 @@ }, | ||
const popCount = isRoot ? 0 : steps.length; | ||
do { | ||
for (let i = 0; i < popCount; i += 1) { | ||
requestHistoryTick(() => { | ||
for (let i = 0; i < popCount; i += 1) { | ||
requestHistoryTick((resolve) => { | ||
if (!safeParseState(getCurrentState({ history }))) { | ||
silentFlag = true; | ||
history.back(); | ||
}); | ||
} | ||
} while (!safeParseState(getCurrentState({ history }))); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
requestHistoryTick(() => { | ||
silentFlag = true; | ||
history.back(); | ||
}); | ||
} | ||
} | ||
@@ -596,0 +606,0 @@ } |
@@ -6,3 +6,3 @@ import type { History } from "history"; | ||
export declare const makeHistoryTaskQueue: (history: History) => { | ||
requestHistoryTick: (action: () => void, listen?: boolean | undefined) => void; | ||
requestHistoryTick: (cb: (resolve: () => void) => void) => void; | ||
}; |
{ | ||
"name": "@stackflow/plugin-history-sync", | ||
"version": "1.3.15", | ||
"version": "1.3.16", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "exports": { |
@@ -11,4 +11,3 @@ import type { History } from "history"; | ||
const requestHistoryTick: HistoryQueueContextValue["requestHistoryTick"] = ( | ||
cb: () => void, | ||
listen: boolean = true, | ||
cb, | ||
) => { | ||
@@ -18,14 +17,11 @@ previousTask = previousTask.then( | ||
new Promise<void>((resolve) => { | ||
if (listen) { | ||
const clean = history.listen(() => { | ||
clean(); | ||
resolve(); | ||
}); | ||
} | ||
const clean = history.listen(() => { | ||
clean(); | ||
resolve(); | ||
}); | ||
cb(); | ||
if (!listen) { | ||
cb(() => { | ||
clean(); | ||
resolve(); | ||
} | ||
}); | ||
}), | ||
@@ -32,0 +28,0 @@ ); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
166845
3157