Skip to content

Commit 93501c7

Browse files
🗑️ - refactor: deprecate public use of getZaakSelection.
1 parent 35f17a1 commit 93501c7

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

frontend/src/lib/zaakSelection/zaakSelection.ts

+31-16
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,6 @@ export async function setAllZakenSelected(key: string, selected: boolean) {
7272
}
7373
}
7474

75-
/**
76-
* Gets the zaak selection.
77-
* Note: only the `url` of selected `zaken` are stored.
78-
* Note: This function is async to accommodate possible future refactors.
79-
* @param key A key identifying the selection
80-
*/
81-
export async function getZaakSelection<DetailType = unknown>(key: string) {
82-
const computedKey = _getComputedKey(key);
83-
const json = sessionStorage.getItem(computedKey) || "{}";
84-
return JSON.parse(json) as ZaakSelection<DetailType>;
85-
}
86-
8775
/**
8876
* Gets the zaak selection, applies a filter to the detail object.
8977
* Note: only the `url` of selected `zaken` are stored.
@@ -97,7 +85,7 @@ export async function getFilteredZaakSelection<DetailType = unknown>(
9785
exp?: Partial<DetailType>,
9886
selectedOnly = true,
9987
) {
100-
const selection = await getZaakSelection<DetailType>(key);
88+
const selection = await _getZaakSelection<DetailType>(key);
10189
const entries = Object.entries(selection);
10290

10391
const filteredEntries = entries.filter(([url, { selected, detail }]) => {
@@ -143,7 +131,7 @@ export async function getZaakSelectionItem<DetailType = unknown>(
143131
zaak: string | Zaak,
144132
selectedOnly = true,
145133
) {
146-
const zaakSelection = await getZaakSelection<DetailType>(key);
134+
const zaakSelection = await _getZaakSelection<DetailType>(key);
147135
const url = _getZaakUrl(zaak);
148136
return zaakSelection[url]?.selected || !selectedOnly
149137
? zaakSelection[url]
@@ -187,7 +175,7 @@ export async function isZaakSelected<DetailType = unknown>(
187175
key: string,
188176
zaak: string | Zaak,
189177
) {
190-
const zaakSelection = await getZaakSelection<DetailType>(key);
178+
const zaakSelection = await _getZaakSelection<DetailType>(key);
191179
const url = _getZaakUrl(zaak);
192180
return zaakSelection[url]?.selected;
193181
}
@@ -215,7 +203,7 @@ export async function _mutateZaakSelection<DetailType = unknown>(
215203
}
216204
}
217205

218-
const currentZaakSelection = await getZaakSelection<DetailType>(key);
206+
const currentZaakSelection = await _getZaakSelection<DetailType>(key);
219207
const urls = _getZaakUrls(zaken);
220208

221209
const zaakSelectionOverrides = urls.reduce<ZaakSelection<DetailType>>(
@@ -237,9 +225,34 @@ export async function _mutateZaakSelection<DetailType = unknown>(
237225
return setZaakSelection(key, combinedZaakSelection);
238226
}
239227

228+
/**
229+
* Gets the zaak selection.
230+
* Note: only the `url` of selected `zaken` are stored.
231+
* Note: This function is async to accommodate possible future refactors.
232+
* @param key A key identifying the selection
233+
* @private
234+
*/
235+
async function _getZaakSelection<DetailType = unknown>(key: string) {
236+
const computedKey = _getComputedKey(key);
237+
const json = sessionStorage.getItem(computedKey) || "{}";
238+
return JSON.parse(json) as ZaakSelection<DetailType>;
239+
}
240+
241+
/**
242+
* @deprecated public use outside `zaakSelection.ts` is deprecated due to performance concerns.
243+
*/
244+
export async function getZaakSelection<DetailType = unknown>(key: string) {
245+
if (process.env.NODE_ENV === "development") {
246+
console.warn("public use of _getZaakSelection is deprecated.");
247+
}
248+
249+
return _getZaakSelection<DetailType>(key);
250+
}
251+
240252
/**
241253
* Computes the prefixed cache key.
242254
* @param key A key identifying the selection
255+
* @private
243256
*/
244257
function _getComputedKey(key: string): string {
245258
return `oab.lib.zaakSelection.${key}`;
@@ -248,6 +261,7 @@ function _getComputedKey(key: string): string {
248261
/**
249262
* Returns the urls based on an `Array` of `string`s or `Zaak` objects.
250263
* @param zaken An array containing either `Zaak.url` or `Zaak` objects
264+
* @private
251265
*/
252266
function _getZaakUrls(zaken: Array<string | Zaak>) {
253267
return zaken.map(_getZaakUrl);
@@ -256,6 +270,7 @@ function _getZaakUrls(zaken: Array<string | Zaak>) {
256270
/**
257271
* Returns the url based on a `string` or `Zaak` object.
258272
* @param zaak Either a `Zaak.url` or `Zaak` object.
273+
* @private
259274
*/
260275
function _getZaakUrl(zaak: string | Zaak) {
261276
return isPrimitive(zaak) ? zaak : (zaak.url as string);

0 commit comments

Comments
 (0)