mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
chore(web): simpler unique ID generation (#9945)
This commit is contained in:
parent
d1135db8cf
commit
1323c7ee88
6 changed files with 8 additions and 36 deletions
|
|
@ -1,14 +0,0 @@
|
|||
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']);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
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