From fe8cb1b693485ef37f9e36d57928ae68fc2ea7a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Thu, 15 Sep 2022 13:28:49 +0000 Subject: [PATCH] refactor: move Model classes --- ui/src/assets/Model.ts | 12 ++++ .../components/calendar/CalendarCarousel.vue | 8 +-- ui/src/components/calendar/CalendarModel.ts | 23 +++++++ ui/src/components/calendar/EventItem.vue | 4 +- ui/src/components/calendar/EventModel.ts | 31 +++++++++ ui/src/components/calendar/model.ts | 64 ------------------- 6 files changed, 72 insertions(+), 70 deletions(-) create mode 100644 ui/src/assets/Model.ts create mode 100644 ui/src/components/calendar/CalendarModel.ts create mode 100644 ui/src/components/calendar/EventModel.ts delete mode 100644 ui/src/components/calendar/model.ts diff --git a/ui/src/assets/Model.ts b/ui/src/assets/Model.ts new file mode 100644 index 0000000..53ca388 --- /dev/null +++ b/ui/src/assets/Model.ts @@ -0,0 +1,12 @@ +export class Model { + public get hash(): string { + const str = JSON.stringify(this); + + // source: https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0?permalink_comment_id=2775538#gistcomment-2775538 + let hash = 0; + for (let i = 0; i < str.length; i++) + hash = Math.imul(31, hash) + str.charCodeAt(i) | 0; + + return new Uint32Array([hash])[0].toString(36); + } +} diff --git a/ui/src/components/calendar/CalendarCarousel.vue b/ui/src/components/calendar/CalendarCarousel.vue index a37c996..9d00441 100644 --- a/ui/src/components/calendar/CalendarCarousel.vue +++ b/ui/src/components/calendar/CalendarCarousel.vue @@ -16,7 +16,7 @@