Implement ClientSchedule state tracking class
Write the logic of keeping track of location modifications and applying updates from the server into the ClientSchedule class. This should serve as the foundation for replacing the prototype in-component update logic which have turned into an unmaintainable spagetti.
This commit is contained in:
parent
aa52a6c651
commit
e100555304
5 changed files with 1005 additions and 1 deletions
|
@ -8,7 +8,7 @@ export const entityLivingSchema = z.object({
|
|||
updatedAt: z.string(),
|
||||
deleted: z.optional(z.literal(false)),
|
||||
});
|
||||
export type EnityLiving = z.infer<typeof entityLivingSchema>;
|
||||
export type EntityLiving = z.infer<typeof entityLivingSchema>;
|
||||
|
||||
export const entityToombstoneSchema = z.object({
|
||||
id: idSchema,
|
||||
|
@ -20,6 +20,9 @@ export type EntityToombstone = z.infer<typeof entityToombstoneSchema>;
|
|||
export const entitySchema = z.discriminatedUnion("deleted", [entityLivingSchema, entityToombstoneSchema]);
|
||||
export type Entity = z.infer<typeof entitySchema>;
|
||||
|
||||
export type Living<T extends Entity> = Extract<T, { deleted?: false }>;
|
||||
export type Tombstone<T extends Entity> = Extract<T, { deleted: true }>;
|
||||
|
||||
export function defineEntity<T extends {}>(fields: T) {
|
||||
return z.discriminatedUnion("deleted", [z.extend(entityLivingSchema, fields), entityToombstoneSchema]);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,29 @@ export function* pairs<T>(iterable: Iterable<T>) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Returns true if the two arrays passed as input compare equal to each other.
|
||||
@param a Input array
|
||||
@param b Input array
|
||||
@param equals Function to compare individual elements in the array.
|
||||
@returns True if the arrays compare equal
|
||||
*/
|
||||
export function arrayEquals<T>(
|
||||
a: T[],
|
||||
b: T[],
|
||||
equals: (a: T, b: T) => unknown = (a, b) => a === b,
|
||||
) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (!equals(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns true if all sets are equal
|
||||
@param sets set to compare
|
||||
|
|
11
shared/utils/luxon.ts
Normal file
11
shared/utils/luxon.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Wrapper around Luxon to make sure the throwOnInvalid option is set
|
||||
import { Settings, DateTime, FixedOffsetZone, Zone } from "luxon";
|
||||
|
||||
Settings.throwOnInvalid = true;
|
||||
declare module 'luxon' {
|
||||
interface TSSettings {
|
||||
throwOnInvalid: true;
|
||||
}
|
||||
}
|
||||
|
||||
export { DateTime, FixedOffsetZone, Zone }
|
Loading…
Add table
Add a link
Reference in a new issue