mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix typing
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
680e1ede98
commit
14d335a984
@ -8,7 +8,7 @@ import { computed } from "mobx";
|
||||
import syncBoxChannelInjectable from "./sync-box-channel.injectable";
|
||||
import { messageToChannelInjectionToken } from "../channel/message-to-channel-injection-token";
|
||||
import syncBoxStateInjectable from "./sync-box-state.injectable";
|
||||
import type { AsJson, SyncBox } from "./sync-box-injection-token";
|
||||
import type { SyncBox } from "./sync-box-injection-token";
|
||||
|
||||
const createSyncBoxInjectable = getInjectable({
|
||||
id: "create-sync-box",
|
||||
@ -18,8 +18,8 @@ const createSyncBoxInjectable = getInjectable({
|
||||
const messageToChannel = di.inject(messageToChannelInjectionToken);
|
||||
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
|
||||
|
||||
return <TData>(id: string, initialValue: AsJson<TData>): SyncBox<TData> => {
|
||||
const state = getSyncBoxState(id) as IObservableValue<AsJson<TData>>;
|
||||
return <Value>(id: string, initialValue: Value): SyncBox<Value> => {
|
||||
const state = getSyncBoxState(id) as IObservableValue<Value>;
|
||||
|
||||
state.set(initialValue);
|
||||
|
||||
|
||||
@ -4,21 +4,10 @@
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { IComputedValue } from "mobx";
|
||||
|
||||
export type AsJson<T> = T extends string | number | boolean | null
|
||||
? T
|
||||
: T extends Function
|
||||
? never
|
||||
: T extends Array<infer V>
|
||||
? AsJson<V>[]
|
||||
: T extends object
|
||||
? { [K in keyof T]: AsJson<T[K]> }
|
||||
: never;
|
||||
|
||||
export interface SyncBox<TValue> {
|
||||
export interface SyncBox<Value> {
|
||||
id: string;
|
||||
value: IComputedValue<AsJson<TValue>>;
|
||||
set: (value: AsJson<TValue>) => void;
|
||||
value: IComputedValue<Value>;
|
||||
set: (value: Value) => void;
|
||||
}
|
||||
|
||||
export const syncBoxInjectionToken = getInjectionToken<SyncBox<any>>({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user