@stackflow/plugin-history-sync
Advanced tools
Comparing version 1.3.10-alpha.0 to 1.3.10-alpha.4
@@ -229,3 +229,2 @@ "use strict"; | ||
let popFlag = 0; | ||
let replacePopCount = 0; | ||
const queue = makeQueue(history); | ||
@@ -530,4 +529,10 @@ return { | ||
const previousActivity = enteredActivities.length > 0 ? enteredActivities[enteredActivities.length - 1] : null; | ||
const popCount = (previousActivity == null ? void 0 : previousActivity.steps.length) ? previousActivity.steps.length : 0; | ||
replacePopCount += popCount; | ||
if (previousActivity) { | ||
popFlag += previousActivity.steps.length - 1; | ||
do { | ||
for (let i = 0; i < previousActivity.steps.length - 1; i += 1) { | ||
queue(history.back); | ||
} | ||
} while (!safeParseState(getCurrentState({ history }))); | ||
} | ||
}, | ||
@@ -546,3 +551,2 @@ onBeforeStepPop({ actions: { getStack } }) { | ||
onBeforePop({ actions: { getStack } }) { | ||
var _a2; | ||
const { activities } = getStack(); | ||
@@ -552,24 +556,12 @@ const currentActivity = activities.find( | ||
); | ||
const enteredActivities = activities.filter( | ||
(activity) => activity.transitionState === "enter-active" || activity.transitionState === "enter-done" | ||
); | ||
const currentActivityIndex = enteredActivities.findIndex( | ||
(activity) => activity.isActive | ||
); | ||
const previousActivity = currentActivityIndex && currentActivityIndex > 0 ? enteredActivities[currentActivityIndex - 1] : null; | ||
const currentStepsLength = (_a2 = currentActivity == null ? void 0 : currentActivity.steps.length) != null ? _a2 : 0; | ||
let popCount = currentStepsLength; | ||
if ((currentActivity == null ? void 0 : currentActivity.enteredBy.name) === "Replaced" && previousActivity) { | ||
const shouldPopForCurrentStepPush = currentStepsLength > 1; | ||
popCount = shouldPopForCurrentStepPush ? replacePopCount + currentStepsLength : replacePopCount; | ||
if (currentActivity) { | ||
const { isRoot, steps } = currentActivity; | ||
const popCount = isRoot ? 0 : steps.length; | ||
popFlag += popCount; | ||
do { | ||
for (let i = 0; i < popCount; i += 1) { | ||
queue(history.back); | ||
} | ||
} while (!safeParseState(getCurrentState({ history }))); | ||
} | ||
popFlag += popCount; | ||
do { | ||
for (let i = 0; i < popCount; i += 1) { | ||
queue(history.back); | ||
} | ||
if ((currentActivity == null ? void 0 : currentActivity.enteredBy.name) === "Replaced" && previousActivity && replacePopCount > 0) { | ||
replacePopCount = 0; | ||
} | ||
} while (!safeParseState(getCurrentState({ history }))); | ||
} | ||
@@ -576,0 +568,0 @@ }; |
{ | ||
"name": "@stackflow/plugin-history-sync", | ||
"version": "1.3.10-alpha.0+4149358a", | ||
"version": "1.3.10-alpha.4+b798553f", | ||
"license": "MIT", | ||
@@ -43,6 +43,6 @@ "exports": { | ||
"devDependencies": { | ||
"@stackflow/core": "^1.0.8-alpha.0+4149358a", | ||
"@stackflow/core": "^1.0.7", | ||
"@stackflow/esbuild-config": "^1.0.0", | ||
"@stackflow/eslint-config": "^1.0.1-alpha.57+4149358a", | ||
"@stackflow/react": "^1.1.5-alpha.0+4149358a", | ||
"@stackflow/eslint-config": "^1.0.0", | ||
"@stackflow/react": "^1.1.4", | ||
"@swc/core": "^1.3.35", | ||
@@ -85,3 +85,3 @@ "@swc/jest": "^0.2.24", | ||
}, | ||
"gitHead": "4149358a851284292ecc2214d0e502713af0daaf" | ||
"gitHead": "b798553f3b1b67004528d6e130abd2201979a367" | ||
} |
@@ -1169,2 +1169,102 @@ import type { | ||
}); | ||
test("historySyncPlugin - push > push > stepPush > pop", async () => { | ||
actions.push({ | ||
activityId: "a1", | ||
activityName: "Article", | ||
activityParams: { | ||
articleId: "1", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s1", | ||
stepParams: { | ||
articleId: "2", | ||
}, | ||
}); | ||
actions.push({ | ||
activityId: "a2", | ||
activityName: "Article", | ||
activityParams: { | ||
articleId: "3", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s2", | ||
stepParams: { | ||
articleId: "4", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s3", | ||
stepParams: { | ||
articleId: "5", | ||
}, | ||
}); | ||
actions.replace({ | ||
activityId: "a3", | ||
activityName: "ThirdActivity", | ||
activityParams: { | ||
thirdId: "1", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s3", | ||
stepParams: { | ||
thirdId: "2", | ||
}, | ||
}); | ||
actions.pop(); | ||
await delay(ENOUGH_DELAY_TIME); | ||
expect(path(history.location)).toEqual("/articles/2/"); | ||
expect(activeActivity(actions.getStack())?.name).toEqual("Article"); | ||
expect(history.index).toEqual(2); | ||
}); | ||
test("historySyncPlugin - push > stepPush > stepPush > replace", async () => { | ||
actions.push({ | ||
activityId: "a1", | ||
activityName: "Article", | ||
activityParams: { | ||
articleId: "1", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s1", | ||
stepParams: { | ||
articleId: "2", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s2", | ||
stepParams: { | ||
articleId: "3", | ||
}, | ||
}); | ||
actions.replace({ | ||
activityId: "a3", | ||
activityName: "ThirdActivity", | ||
activityParams: { | ||
thirdId: "1", | ||
}, | ||
}); | ||
await delay(ENOUGH_DELAY_TIME); | ||
expect(path(history.location)).toEqual("/third/1/"); | ||
expect(activeActivity(actions.getStack())?.name).toEqual("ThirdActivity"); | ||
expect(history.index).toEqual(1); | ||
}); | ||
}); |
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
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
2979
155967