mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 23:19:09 +00:00
refactor: cleanup store (#727)
* refactor: isolate clock * refactor: isolate private * refactor: remove duplicate * chore: rename loaded > runtime * fix: handle no events loaded
This commit is contained in:
@@ -3,22 +3,19 @@ import { Playback, RuntimeStore } from 'ontime-types';
|
||||
import { createWithEqualityFn, useStoreWithEqualityFn } from 'zustand/traditional';
|
||||
|
||||
export const runtimeStorePlaceholder: RuntimeStore = {
|
||||
clock: 0,
|
||||
timer: {
|
||||
clock: 0,
|
||||
addedTime: 0,
|
||||
current: null,
|
||||
duration: null,
|
||||
elapsed: null,
|
||||
expectedFinish: null,
|
||||
addedTime: 0,
|
||||
startedAt: null,
|
||||
finishedAt: null,
|
||||
playback: Playback.Stop,
|
||||
secondaryTimer: null,
|
||||
duration: null,
|
||||
timerType: null,
|
||||
endAction: null,
|
||||
timeWarning: null,
|
||||
timeDanger: null,
|
||||
startedAt: null,
|
||||
},
|
||||
playback: Playback.Stop,
|
||||
onAir: false,
|
||||
message: {
|
||||
timer: {
|
||||
text: '',
|
||||
@@ -39,14 +36,9 @@ export const runtimeStorePlaceholder: RuntimeStore = {
|
||||
visible: false,
|
||||
},
|
||||
},
|
||||
onAir: false,
|
||||
loaded: {
|
||||
runtime: {
|
||||
numEvents: 0,
|
||||
selectedEventIndex: null,
|
||||
selectedEventId: null,
|
||||
selectedPublicEventId: null,
|
||||
nextEventId: null,
|
||||
nextPublicEventId: null,
|
||||
},
|
||||
eventNow: null,
|
||||
eventNext: null,
|
||||
@@ -56,7 +48,7 @@ export const runtimeStorePlaceholder: RuntimeStore = {
|
||||
|
||||
const deepCompare = <T>(a: T, b: T) => isEqual(a, b);
|
||||
|
||||
export const runtime = createWithEqualityFn<RuntimeStore>(
|
||||
export const runtimeStore = createWithEqualityFn<RuntimeStore>(
|
||||
() => ({
|
||||
...runtimeStorePlaceholder,
|
||||
}),
|
||||
@@ -64,4 +56,4 @@ export const runtime = createWithEqualityFn<RuntimeStore>(
|
||||
);
|
||||
|
||||
export const useRuntimeStore = <T>(selector: (state: RuntimeStore) => T) =>
|
||||
useStoreWithEqualityFn(runtime, selector, deepCompare);
|
||||
useStoreWithEqualityFn(runtimeStore, selector, deepCompare);
|
||||
|
||||
Reference in New Issue
Block a user