Skip to content

Commit

Permalink
fix initial subview not applied on subview push
Browse files Browse the repository at this point in the history
  • Loading branch information
XiNiHa committed Nov 11, 2024
1 parent 67b2172 commit 70a3bb0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-ways-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@contentstech/stackflow-plugin-omniflow": patch
---

Fix initial subview not applied on subview push
71 changes: 36 additions & 35 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,27 @@ export function omniflow<ActivityName extends string>({
return activityOptions?.[environment];
};

function getOmniInitialParams(activityName: ActivityName) {
function impl(activityName: ActivityName):
| {
childName: ActivityName[];
childParams: ActivityBaseParams[];
}
| undefined {
const envOptions = getEnvOptions(activityName);
if (envOptions?.subview.initialActivity) {
const { childName, childParams } =
impl(envOptions.subview.initialActivity.name) ?? {};
return {
childName: [
envOptions.subview.initialActivity.name,
...(childName ?? []),
],
childParams: [
envOptions.subview.initialActivity.params,
...(childParams ?? []),
],
};
}
function getOmniInitialParams(activityName: ActivityName):
| {
childName: ActivityName[];
childParams: ActivityBaseParams[];
}
| undefined {
const envOptions = getEnvOptions(activityName);
if (envOptions?.subview.initialActivity) {
const { childName, childParams } =
getOmniInitialParams(envOptions.subview.initialActivity.name) ?? {};
return {
childName: [
envOptions.subview.initialActivity.name,
...(childName ?? []),
],
childParams: [
envOptions.subview.initialActivity.params,
...(childParams ?? []),
],
};
}

const result = impl(activityName);
return {
OMNI_childName: JSON.stringify(result?.childName),
OMNI_childParams: JSON.stringify(result?.childParams),
};
}

function getOmniStepParams(
Expand All @@ -101,14 +93,18 @@ export function omniflow<ActivityName extends string>({
const activityName = iterStack[i];
const envOptions = getEnvOptions(activityName);
if (envOptions?.subview.children?.includes(newActivityName)) {
const newInitialParams = getOmniInitialParams(newActivityName);

return {
OMNI_childName: JSON.stringify([
...childNameStack.slice(0, i),
newActivityName,
...(newInitialParams?.childName ?? []),
]),
OMNI_childParams: JSON.stringify([
...childParamsStack.slice(0, i),
newActivityParams,
...(newInitialParams?.childParams ?? []),
]),
};
}
Expand All @@ -122,11 +118,14 @@ export function omniflow<ActivityName extends string>({
(e) => e.name === "Pushed",
);
if (topActivityEvent) {
const omniParams = getOmniInitialParams(
const initialParams = getOmniInitialParams(
topActivityEvent.activityName as ActivityName,
);
if (omniParams) {
topActivityEvent.activityParams = omniParams;
if (initialParams) {
topActivityEvent.activityParams = {
OMNI_childName: JSON.stringify(initialParams.childName),
OMNI_childParams: JSON.stringify(initialParams.childParams),
};
}
}
return initialEvents;
Expand Down Expand Up @@ -154,7 +153,8 @@ export function omniflow<ActivityName extends string>({
...actionParams,
activityParams: {
...actionParams.activityParams,
...initialParams,
OMNI_childName: JSON.stringify(initialParams.childName),
OMNI_childParams: JSON.stringify(initialParams.childParams),
},
});
}
Expand All @@ -174,15 +174,16 @@ export function omniflow<ActivityName extends string>({
}
}

const omniParams = getOmniInitialParams(
const initialParams = getOmniInitialParams(
actionParams.activityName as ActivityName,
);
if (omniParams) {
if (initialParams) {
actions.overrideActionParams({
...actionParams,
activityParams: {
...actionParams.activityParams,
...omniParams,
OMNI_childName: JSON.stringify(initialParams.childName),
OMNI_childParams: JSON.stringify(initialParams.childParams),
},
});
}
Expand Down

0 comments on commit 70a3bb0

Please sign in to comment.