@stackflow/plugin-history-sync
Advanced tools
Comparing version 1.1.1-alpha.2 to 1.2.0
@@ -175,2 +175,26 @@ "use strict"; | ||
// src/queue.ts | ||
var makeQueue = (history) => { | ||
let pending = false; | ||
const queue = (cb) => { | ||
const start = () => { | ||
pending = true; | ||
const clean = history.listen(() => { | ||
clean(); | ||
pending = false; | ||
}); | ||
cb(); | ||
}; | ||
if (pending) { | ||
const clean = history.listen(() => { | ||
clean(); | ||
start(); | ||
}); | ||
} else { | ||
start(); | ||
} | ||
}; | ||
return queue; | ||
}; | ||
// src/RoutesContext.tsx | ||
@@ -199,2 +223,3 @@ var import_react = require("react"); | ||
let popFlag = 0; | ||
const queue = makeQueue(history); | ||
return { | ||
@@ -287,11 +312,13 @@ key: "plugin-history-sync", | ||
const lastStep = last(rootActivity.steps); | ||
replaceState({ | ||
history, | ||
pathname: template.fill(rootActivity.params), | ||
state: { | ||
activity: rootActivity, | ||
step: lastStep | ||
}, | ||
useHash: options.useHash | ||
}); | ||
queue( | ||
() => replaceState({ | ||
history, | ||
pathname: template.fill(rootActivity.params), | ||
state: { | ||
activity: rootActivity, | ||
step: lastStep | ||
}, | ||
useHash: options.useHash | ||
}) | ||
); | ||
const onPopState = (e) => { | ||
@@ -398,10 +425,12 @@ if (popFlag) { | ||
); | ||
pushState({ | ||
history, | ||
pathname: template.fill(activity.params), | ||
state: { | ||
activity | ||
}, | ||
useHash: options.useHash | ||
}); | ||
queue( | ||
() => pushState({ | ||
history, | ||
pathname: template.fill(activity.params), | ||
state: { | ||
activity | ||
}, | ||
useHash: options.useHash | ||
}) | ||
); | ||
}, | ||
@@ -417,11 +446,13 @@ onStepPushed({ effect: { activity, step } }) { | ||
); | ||
pushState({ | ||
history, | ||
pathname: template.fill(activity.params), | ||
state: { | ||
activity, | ||
step | ||
}, | ||
useHash: options.useHash | ||
}); | ||
queue( | ||
() => pushState({ | ||
history, | ||
pathname: template.fill(activity.params), | ||
state: { | ||
activity, | ||
step | ||
}, | ||
useHash: options.useHash | ||
}) | ||
); | ||
}, | ||
@@ -436,10 +467,12 @@ onReplaced({ effect: { activity } }) { | ||
); | ||
replaceState({ | ||
history, | ||
pathname: template.fill(activity.params), | ||
state: { | ||
activity | ||
}, | ||
useHash: options.useHash | ||
}); | ||
queue( | ||
() => replaceState({ | ||
history, | ||
pathname: template.fill(activity.params), | ||
state: { | ||
activity | ||
}, | ||
useHash: options.useHash | ||
}) | ||
); | ||
}, | ||
@@ -454,11 +487,13 @@ onStepReplaced({ effect: { activity, step } }) { | ||
); | ||
replaceState({ | ||
history, | ||
pathname: template.fill(activity.params), | ||
state: { | ||
activity, | ||
step | ||
}, | ||
useHash: options.useHash | ||
}); | ||
queue( | ||
() => replaceState({ | ||
history, | ||
pathname: template.fill(activity.params), | ||
state: { | ||
activity, | ||
step | ||
}, | ||
useHash: options.useHash | ||
}) | ||
); | ||
}, | ||
@@ -497,3 +532,3 @@ onBeforePush({ actionParams, actions: { overrideActionParams } }) { | ||
popFlag += 1; | ||
history.back(); | ||
queue(history.back); | ||
} | ||
@@ -511,3 +546,3 @@ }, | ||
for (let i = 0; i < popCount; i += 1) { | ||
history.back(); | ||
queue(history.back); | ||
} | ||
@@ -514,0 +549,0 @@ } while (!safeParseState(getCurrentState({ history }))); |
{ | ||
"name": "@stackflow/plugin-history-sync", | ||
"version": "1.1.1-alpha.2+e3b0f3bc", | ||
"version": "1.2.0", | ||
"license": "MIT", | ||
@@ -41,6 +41,6 @@ "exports": { | ||
"devDependencies": { | ||
"@stackflow/core": "^1.0.2", | ||
"@stackflow/core": "^1.0.3", | ||
"@stackflow/esbuild-config": "^1.0.0", | ||
"@stackflow/eslint-config": "^1.0.0", | ||
"@stackflow/react": "^1.0.2", | ||
"@stackflow/react": "^1.0.3", | ||
"@swc/core": "^1.3.35", | ||
@@ -83,3 +83,3 @@ "@swc/jest": "^0.2.24", | ||
}, | ||
"gitHead": "e3b0f3bc3fc896bebf1ba59b016689e6917679f1" | ||
"gitHead": "11774f22968cea55a1e287bbf07096ce0e5e0f5f" | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
136886
31
2345
1