@stackflow/plugin-history-sync
Advanced tools
Comparing version 1.3.4 to 1.3.5
@@ -62,3 +62,3 @@ "use strict"; | ||
// src/historyState.ts | ||
var STATE_TAG = `${"@stackflow/plugin-history-sync"}@${"1.3.3"}`; | ||
var STATE_TAG = `${"@stackflow/plugin-history-sync"}@${"1.3.4"}`; | ||
function serializeStep(step) { | ||
@@ -542,3 +542,16 @@ return __spreadProps(__spreadValues({}, step), { | ||
); | ||
const popCount = (_a2 = currentActivity == null ? void 0 : currentActivity.steps.length) != null ? _a2 : 0; | ||
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 previousStepsLength = previousActivity.steps.length; | ||
const replacedActivityDepth = 1; | ||
popCount = currentStepsLength + previousStepsLength - replacedActivityDepth; | ||
} | ||
popFlag += popCount; | ||
@@ -545,0 +558,0 @@ do { |
{ | ||
"name": "@stackflow/plugin-history-sync", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"license": "MIT", | ||
@@ -84,3 +84,3 @@ "exports": { | ||
}, | ||
"gitHead": "cbe7f49c46bea3ab37550626dcd44ea9cca7f930" | ||
"gitHead": "9f0cbe88880ec2ddc654fdb87c0f459e68b6ff3a" | ||
} |
@@ -24,2 +24,8 @@ import type { | ||
async function delay(ms: number) { | ||
return new Promise<void>((res) => { | ||
setTimeout(res, ms); | ||
}); | ||
} | ||
const path = (location: Location) => | ||
@@ -92,3 +98,3 @@ location.pathname + location.search + location.hash; | ||
const coreStore = stackflow({ | ||
activityNames: ["Home", "Article"], | ||
activityNames: ["Home", "Article", "ThirdActivity", "FourthActivity"], | ||
plugins: [ | ||
@@ -100,2 +106,4 @@ historySyncPlugin({ | ||
Article: "/articles/:articleId", | ||
ThirdActivity: "/third/:thirdId", | ||
FourthActivity: "/fourth/:fourthId", | ||
}, | ||
@@ -627,2 +635,187 @@ fallbackActivity: () => "Home", | ||
}); | ||
test("historySyncPlugin - push 후 stepPush 를 반복한 뒤, replace 를 하고 pop 을 수행하면 첫번째 stack 을 가리킵니다.", async () => { | ||
actions.push({ | ||
activityId: "a2", | ||
activityName: "Article", | ||
activityParams: { | ||
articleId: "1", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s2", | ||
stepParams: { | ||
articleId: "2", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s3", | ||
stepParams: { | ||
articleId: "3", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s4", | ||
stepParams: { | ||
articleId: "4", | ||
}, | ||
}); | ||
actions.replace({ | ||
activityId: "a3", | ||
activityName: "ThirdActivity", | ||
activityParams: { | ||
thirdId: "234", | ||
}, | ||
}); | ||
actions.pop(); | ||
// 전환이 끝나기까지 충분한 시간 | ||
// 코어쪽 추가된 테스트 코드가 Resolve 되면 삭제 가능 | ||
await delay(32 + 16); | ||
expect(path(history.location)).toEqual("/home/"); | ||
expect(activeActivity(actions.getStack())?.name).toEqual("Home"); | ||
}); | ||
test("historySyncPlugin - push 후 stepPush 를 반복한 뒤, push 와 pop 을 1회 수행하고 replace를 수행하고 pop 을 진행하면 첫번째 stack 을 가리킵니다.", async () => { | ||
actions.push({ | ||
activityId: "a2", | ||
activityName: "Article", | ||
activityParams: { | ||
articleId: "1", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s2", | ||
stepParams: { | ||
articleId: "2", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s3", | ||
stepParams: { | ||
articleId: "3", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s4", | ||
stepParams: { | ||
articleId: "4", | ||
}, | ||
}); | ||
actions.push({ | ||
activityId: "a3", | ||
activityName: "ThirdActivity", | ||
activityParams: { | ||
thirdId: "234", | ||
}, | ||
}); | ||
actions.pop(); | ||
actions.replace({ | ||
activityId: "a4", | ||
activityName: "FourthActivity", | ||
activityParams: { | ||
fourthId: "345", | ||
}, | ||
}); | ||
actions.pop(); | ||
// 전환이 끝나기까지 충분한 시간 | ||
// 코어쪽 추가된 테스트 코드가 Resolve 되면 삭제 가능 | ||
await delay(16 * 5); | ||
expect(path(history.location)).toEqual("/home/"); | ||
expect(activeActivity(actions.getStack())?.name).toEqual("Home"); | ||
}) | ||
test("historySyncPlugin - push 후 stepPush 를 반복한 뒤, push 와 pop 을 1회 수행하고 replace 를 한 뒤 stepPush 를 반복하고 pop 을 진행해도 첫번째 stack 을 가리킵니다.", async () => { | ||
actions.push({ | ||
activityId: "a2", | ||
activityName: "Article", | ||
activityParams: { | ||
articleId: "1", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s2", | ||
stepParams: { | ||
articleId: "2", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s3", | ||
stepParams: { | ||
articleId: "3", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s4", | ||
stepParams: { | ||
articleId: "4", | ||
}, | ||
}); | ||
actions.push({ | ||
activityId: "a3", | ||
activityName: "ThirdActivity", | ||
activityParams: { | ||
thirdId: "234", | ||
}, | ||
}); | ||
actions.pop(); | ||
actions.replace({ | ||
activityId: "a4", | ||
activityName: "FourthActivity", | ||
activityParams: { | ||
fourthId: "345", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s5", | ||
stepParams: { | ||
fourthId: "5", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s6", | ||
stepParams: { | ||
fourthId: "6", | ||
}, | ||
}); | ||
actions.stepPush({ | ||
stepId: "s7", | ||
stepParams: { | ||
fourthId: "7", | ||
}, | ||
}); | ||
actions.pop(); | ||
// 전환이 끝나기까지 충분한 시간 | ||
// 코어쪽 추가된 테스트 코드가 Resolve 되면 삭제 가능 | ||
await delay(16 * 7); | ||
expect(path(history.location)).toEqual("/home/"); | ||
expect(activeActivity(actions.getStack())?.name).toEqual("Home"); | ||
}) | ||
}); |
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
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
149219
2591