Skip to content

Commit

Permalink
refactor: simplify zone type forcing
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Sep 3, 2024
1 parent d3466e3 commit e4cca94
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions packages/core/lib/setup-zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ import { rootDroppableId } from "./root-droppable-id";
// Force 'zones' to always be present and non-undefined
type WithZones<T extends Data> = T & { zones: NonNullable<T["zones"]> };

// Ensuring zones is non-undefined and part of the final type
function ensureZones<UserData extends Data>(
data: UserData
): WithZones<UserData> {
return {
...data,
zones: data.zones || {},
} as WithZones<UserData>;
}

export const setupZone = <UserData extends Data>(
data: UserData,
zoneKey: string
Expand All @@ -23,7 +13,10 @@ export const setupZone = <UserData extends Data>(
}

// Preprocess to ensure zones is not undefined
const newData = ensureZones(data);
const newData = {
...data,
zones: data.zones || {},
};

newData.zones[zoneKey] = newData.zones[zoneKey] || [];

Expand Down

0 comments on commit e4cca94

Please sign in to comment.