Skip to content

Commit

Permalink
fix: Allow views to get their specific ephemeral stores back
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Apr 11, 2024
1 parent 1a3dda4 commit 0730445
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/stores/calendar.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export type CalendarStore = ReturnType<typeof createCalendarStore>;
export interface CalendarStoreState {
ephemeral: EphemeralState;
calendar: string;
id: string;
child?: string;
}
export function createCalendarStore(calendar: Calendar, plugin: Calendarium) {
const store = writable(calendar);
Expand All @@ -54,18 +56,27 @@ export function createCalendarStore(calendar: Calendar, plugin: Calendarium) {
);
const moonCache = new MoonCache(moonStates, yearCalculator);

let ephemeralStore = getEphemeralStore(
store,
staticStore,
calendar,
yearCalculator
);
const EPHEMERAL_STORE_CACHE: Map<string, EphemeralStore> = new Map();

const _getEphemeralStore = (id: string) => {
if (EPHEMERAL_STORE_CACHE.has(id)) {
return EPHEMERAL_STORE_CACHE.get(id)!;
}
const ephemeralStore = getEphemeralStore(
store,
staticStore,
calendar,
yearCalculator
);
EPHEMERAL_STORE_CACHE.set(id, ephemeralStore);
return ephemeralStore;
};

return {
getStoreState: () => {
getStoreState: (id: string) => {
return {
calendar: calendar.id,
ephemeral: ephemeralStore.getEphemeralState(),
ephemeral: _getEphemeralStore(id).getEphemeralState(),
};
},

Expand Down Expand Up @@ -137,16 +148,7 @@ export function createCalendarStore(calendar: Calendar, plugin: Calendarium) {
//Readable store containing static calendar data
staticStore,

ephemeralStore,
getEphemeralStore: () => {
ephemeralStore = getEphemeralStore(
store,
staticStore,
calendar,
yearCalculator
);
return ephemeralStore;
},
getEphemeralStore: _getEphemeralStore,
yearCalculator,
hasCategory: (category: string) =>
get(categories).find((f) => f.id === category) != null,
Expand Down

0 comments on commit 0730445

Please sign in to comment.