mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
chore(web): unique ID generation (#9932)
* chore(web): automatically generate unique IDs * fix: revert changes to Slider * chore: add test for id store
This commit is contained in:
parent
4e16e2520d
commit
01f52c9021
52 changed files with 83 additions and 150 deletions
14
web/src/lib/stores/unique-id.store.spec.ts
Normal file
14
web/src/lib/stores/unique-id.store.spec.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { uniqueIdStore } from '$lib/stores/unique-id.store';
|
||||
|
||||
describe('uniqueIdStore', () => {
|
||||
afterEach(() => {
|
||||
uniqueIdStore.update(() => -1);
|
||||
});
|
||||
|
||||
it('should generate unique ids', () => {
|
||||
const { generateId } = uniqueIdStore;
|
||||
const ids = [generateId(), generateId(), generateId()];
|
||||
|
||||
expect(ids).toEqual(['id-0', 'id-1', 'id-2']);
|
||||
});
|
||||
});
|
||||
16
web/src/lib/stores/unique-id.store.ts
Normal file
16
web/src/lib/stores/unique-id.store.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { get, writable } from 'svelte/store';
|
||||
|
||||
function createIdStore() {
|
||||
const { subscribe, update } = writable(-1);
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
update,
|
||||
generateId: () => {
|
||||
update((value) => value + 1);
|
||||
return `id-${get(uniqueIdStore)}`;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const uniqueIdStore = createIdStore();
|
||||
Loading…
Add table
Add a link
Reference in a new issue