Skip to content

Commit b76885a

Browse files
committed
refactor: restructure flow action handling in initRouteListener
1 parent 463915e commit b76885a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/lib/pipeline.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export type HookFunc = (type: 'request' | 'response', text: any, flow: Flow) =>
99
const originalFetch = (typeof unsafeWindow !== 'undefined' ? unsafeWindow : window).fetch;
1010

1111
export function initRouteListener(hook: HookFunc) {
12-
listenUrlChange(async ({ uuid, action }) => {
12+
// 处理单个 flow action 的逻辑
13+
const handleFlowAction = async ({ uuid, action }: CallAction) => {
1314
const flow = await getFlow(uuid);
1415
if (!flow) {
1516
return;
@@ -18,7 +19,16 @@ export function initRouteListener(hook: HookFunc) {
1819
const dataUrl = `http://${window.location.host}/flows/${uuid}/${action}/content/Auto.json`;
1920
const data = await getFlowData(dataUrl);
2021
hook(action, data, flow);
21-
});
22+
};
23+
24+
// 初始化时检查当前 URL
25+
const currentFlow = extractFlowInfo(location.href);
26+
if (currentFlow) {
27+
handleFlowAction(currentFlow);
28+
}
29+
30+
// 监听 URL 变化
31+
listenUrlChange(handleFlowAction);
2232
}
2333

2434
function extractFlowInfo(url: string): CallAction | null {

0 commit comments

Comments
 (0)