From 70a3bb023564d5f67a0883a04295ec52fa2056ba Mon Sep 17 00:00:00 2001 From: Iha Shin Date: Tue, 12 Nov 2024 04:19:53 +0900 Subject: [PATCH] fix initial subview not applied on subview push --- .changeset/three-ways-study.md | 5 +++ src/index.tsx | 71 +++++++++++++++++----------------- 2 files changed, 41 insertions(+), 35 deletions(-) create mode 100644 .changeset/three-ways-study.md diff --git a/.changeset/three-ways-study.md b/.changeset/three-ways-study.md new file mode 100644 index 0000000..58f0d86 --- /dev/null +++ b/.changeset/three-ways-study.md @@ -0,0 +1,5 @@ +--- +"@contentstech/stackflow-plugin-omniflow": patch +--- + +Fix initial subview not applied on subview push diff --git a/src/index.tsx b/src/index.tsx index d8d1fe2..1ab6b37 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -51,35 +51,27 @@ export function omniflow({ 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( @@ -101,14 +93,18 @@ export function omniflow({ 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 ?? []), ]), }; } @@ -122,11 +118,14 @@ export function omniflow({ (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; @@ -154,7 +153,8 @@ export function omniflow({ ...actionParams, activityParams: { ...actionParams.activityParams, - ...initialParams, + OMNI_childName: JSON.stringify(initialParams.childName), + OMNI_childParams: JSON.stringify(initialParams.childParams), }, }); } @@ -174,15 +174,16 @@ export function omniflow({ } } - 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), }, }); }