Minor refactors
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { UserId } from "common";
|
||||
import * as Function from "common/Function";
|
||||
import { identity } from "effect";
|
||||
import { useLayoutEffect, useState } from "react";
|
||||
|
||||
export type Update<T> = T | ((prev: T) => T);
|
||||
@@ -19,14 +19,16 @@ export namespace Store {
|
||||
|
||||
export interface Store {
|
||||
readonly user: Store.User | null;
|
||||
readonly setUser: Updater<Store.User | null>;
|
||||
}
|
||||
|
||||
let store: Store = Object.freeze<Store>({
|
||||
user: null,
|
||||
setUser: (action) => set(mapProp("user", action)),
|
||||
});
|
||||
|
||||
export function setUser(action: Update<Store.User | null>) {
|
||||
set(mapProp("user", action));
|
||||
}
|
||||
|
||||
// --- STORE IMPLEMENTATION ----------------------------------------------------
|
||||
|
||||
class Listener<T> {
|
||||
@@ -64,7 +66,7 @@ function set(action: Partial<Store> | ((store: Store) => Partial<Store>), replac
|
||||
}
|
||||
}
|
||||
|
||||
export function useStore<T = Store>(selector: Selector<T> = Function.identity as Selector<T>): T {
|
||||
export function useStore<T = Store>(selector: Selector<T> = identity as Selector<T>): T {
|
||||
|
||||
const [state, setState] = useState(() => selector(store));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user