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 syncBoxChannelInjectable from "./sync-box-channel.injectable";
|
||||||
import { messageToChannelInjectionToken } from "../channel/message-to-channel-injection-token";
|
import { messageToChannelInjectionToken } from "../channel/message-to-channel-injection-token";
|
||||||
import syncBoxStateInjectable from "./sync-box-state.injectable";
|
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({
|
const createSyncBoxInjectable = getInjectable({
|
||||||
id: "create-sync-box",
|
id: "create-sync-box",
|
||||||
@ -18,8 +18,8 @@ const createSyncBoxInjectable = getInjectable({
|
|||||||
const messageToChannel = di.inject(messageToChannelInjectionToken);
|
const messageToChannel = di.inject(messageToChannelInjectionToken);
|
||||||
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
|
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
|
||||||
|
|
||||||
return <TData>(id: string, initialValue: AsJson<TData>): SyncBox<TData> => {
|
return <Value>(id: string, initialValue: Value): SyncBox<Value> => {
|
||||||
const state = getSyncBoxState(id) as IObservableValue<AsJson<TData>>;
|
const state = getSyncBoxState(id) as IObservableValue<Value>;
|
||||||
|
|
||||||
state.set(initialValue);
|
state.set(initialValue);
|
||||||
|
|
||||||
|
|||||||
@ -4,21 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
import type { IComputedValue } from "mobx";
|
import type { IComputedValue } from "mobx";
|
||||||
|
export interface SyncBox<Value> {
|
||||||
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> {
|
|
||||||
id: string;
|
id: string;
|
||||||
value: IComputedValue<AsJson<TValue>>;
|
value: IComputedValue<Value>;
|
||||||
set: (value: AsJson<TValue>) => void;
|
set: (value: Value) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const syncBoxInjectionToken = getInjectionToken<SyncBox<any>>({
|
export const syncBoxInjectionToken = getInjectionToken<SyncBox<any>>({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user