Merge feature/svelte into develop

This commit is contained in:
Pieter Vander Vennet 2023-03-08 19:02:41 +01:00
commit 868d476891
120 changed files with 5168 additions and 10657 deletions

View file

@ -1,4 +1,5 @@
import { Utils } from "../Utils"
import { Readable, Subscriber, Unsubscriber } from "svelte/store"
/**
* Various static utils
@ -88,7 +89,7 @@ export class Stores {
}
}
export abstract class Store<T> {
export abstract class Store<T> implements Readable<T> {
abstract readonly data: T
/**
@ -113,6 +114,18 @@ export abstract class Store<T> {
abstract map<J>(f: (t: T) => J): Store<J>
abstract map<J>(f: (t: T) => J, extraStoresToWatch: Store<any>[]): Store<J>
public mapD<J>(f: (t: T) => J, extraStoresToWatch?: Store<any>[]): Store<J> {
return this.map((t) => {
if (t === undefined) {
return undefined
}
if (t === null) {
return null
}
return f(t)
}, extraStoresToWatch)
}
/**
* Add a callback function which will run on future data changes
*/
@ -258,6 +271,17 @@ export abstract class Store<T> {
}
})
}
/**
* Same as 'addCallbackAndRun', added to be compatible with Svelte
* @param run
* @param invalidate
*/
public subscribe(run: Subscriber<T> & ((value: T) => void), invalidate?): Unsubscriber {
// We don't need to do anything with 'invalidate', see
// https://github.com/sveltejs/svelte/issues/3859
return this.addCallbackAndRun(run)
}
}
export class ImmutableStore<T> extends Store<T> {