Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfromundefined committed Dec 26, 2024
1 parent 17e6e41 commit 761b26d
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions core/src/activity-utils/makeStackReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function makeStackReducer(context: {
transitionDuration: context.initializedEvent.transitionDuration,
now: context.now,
});
const activityReducer = makeActivityReducer({
transitionDuration: context.initializedEvent.transitionDuration,
now: context.now,
});

let _isPaused = false;

Expand Down Expand Up @@ -48,46 +52,36 @@ export function makeStackReducer(context: {
_isPaused = false;
}

const prevActivities = stack.activities;
const nextActivities = uniqBy(
activitiesReducer(prevActivities, event),
(activity) => activity.id,
);

const activities = activitiesReducer(stack.activities, event);
const targetActivityIndices = findTargetActivityIndices(
prevActivities,
stack.activities,
event,
{
transitionDuration: stack.transitionDuration,
now: context.now,
},
{ transitionDuration: stack.transitionDuration, now: context.now },
);

const activityReducer = makeActivityReducer({
transitionDuration: stack.transitionDuration,
now: context.now,
});

targetActivityIndices.forEach((targetIdx) => {
nextActivities[targetIdx] = activityReducer(
nextActivities[targetIdx],
for (const targetActivityIndex of targetActivityIndices) {
activities[targetActivityIndex] = activityReducer(
activities[targetActivityIndex],
event,
);
});
}

const isPaused = _isPaused;
const isLoading = activities.find(
(activity) =>
activity.transitionState === "enter-active" ||
activity.transitionState === "exit-active",
);

const globalTransitionState = _isPaused
const globalTransitionState = isPaused
? "paused"
: nextActivities.find(
(activity) =>
activity.transitionState === "enter-active" ||
activity.transitionState === "exit-active",
)
: isLoading
? "loading"
: "idle";

return {
...stack,
activities: nextActivities,
activities: uniqBy(activities, (activity) => activity.id),
globalTransitionState,
};
}
Expand Down

0 comments on commit 761b26d

Please sign in to comment.