Skip to content

Commit

Permalink
fix: add ts lint
Browse files Browse the repository at this point in the history
  • Loading branch information
hqer927 committed Nov 25, 2024
1 parent 91e98a3 commit fcde603
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 6,308 deletions.
7 changes: 4 additions & 3 deletions packages/app-embedded-page-sdk/src/EmbeddedApp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type {
CameraState,
DefaultState,
Expand All @@ -15,7 +16,7 @@ import type {
import type { Logger } from "@netless/app-shared";
import { SideEffectManager } from "side-effect-manager";
import { EmbeddedPageEvent } from "./EmbeddedPageEvent";
import type { Store } from "./Store/Store";
import type { Store, TStateLike } from "./Store/Store";
import { StoreImpl } from "./Store/Store";
import type { MaybeRefValue } from "./utils";
import { has } from "./utils";
Expand Down Expand Up @@ -185,7 +186,7 @@ export class EmbeddedApp<TState extends object = DefaultState, TMessage = unknow

private _stores = new Map<string, Store>();

connectStore<S>(storeId: string, ensureState?: S): Store<S> {
connectStore<S extends TStateLike>(storeId: string, ensureState?: S): Store<S> {
let store = this._stores.get(storeId) as Store<S> | undefined;
if (!store) {
if (!has(this._storeRawData, storeId)) {
Expand Down Expand Up @@ -244,7 +245,7 @@ export class EmbeddedApp<TState extends object = DefaultState, TMessage = unknow
const store = this._stores.get(key);
if (store) {
this._stores.delete(key);
(store as StoreImpl)._destroy();
(store as any)._destroy();
}
break;
}
Expand Down
10 changes: 8 additions & 2 deletions packages/app-embedded-page-sdk/src/Store/Store.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Diff } from "@netless/app-embedded-page";
import type { Logger } from "@netless/app-shared";
import type { AkkoObjectUpdatedProperty } from "white-web-sdk";
import { EmbeddedPageEvent } from "../EmbeddedPageEvent";
import type { MaybeRefValue } from "../utils";
import { has, isObj, isRef, makeRef, plainObjectKeys } from "../utils";


export interface TStateLike {
[key: string]: any;
}

export type StoreOnSetStatePayload<TState = unknown> = {
[K in keyof TState]?: MaybeRefValue<TState[K]>;
};

export type StoreStateChangedPayload<TState = unknown> = ReadonlyArray<
export type StoreStateChangedPayload<TState extends TStateLike> = ReadonlyArray<
AkkoObjectUpdatedProperty<TState, Extract<keyof TState, string>>
>;

Expand All @@ -33,7 +39,7 @@ export interface StoreConfig<TState = unknown> {
logger?: Logger | Console;
}

export class StoreImpl<TState = unknown> implements Store<TState> {
export class StoreImpl<TState extends TStateLike> implements Store<TState> {
readonly id: string;
getIsWritable: StoreConfig["getIsWritable"];

Expand Down
9 changes: 7 additions & 2 deletions packages/app-shared/src/ensure-attributes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { AppContext } from "@netless/window-manager";

function isObject(val: unknown): val is Record<string, unknown> {
return val != null && typeof val === "object" && !Array.isArray(val);
}

export function ensureAttributes<T>(context: AppContext<T>, initAttrs: T): T {
export interface Attributes {
[key: string]: any;
}

export function ensureAttributes<T extends Attributes>(context: AppContext<T>, initAttrs: T): T {
let attrs = context.getAttributes();
if (!attrs) {
context.setAttributes(initAttrs);
Expand All @@ -16,7 +21,7 @@ export function ensureAttributes<T>(context: AppContext<T>, initAttrs: T): T {
if (isObject(initAttrs)) {
Object.keys(initAttrs).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(attrs, key)) {
context.updateAttributes([key], initAttrs[key]);
context.updateAttributes([key], initAttrs[key] as {});
}
});
}
Expand Down
15 changes: 0 additions & 15 deletions packages/app-slide/example/.eslintrc.cjs

This file was deleted.

24 changes: 0 additions & 24 deletions packages/app-slide/example/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions packages/app-slide/example/README.md

This file was deleted.

15 changes: 0 additions & 15 deletions packages/app-slide/example/index.html

This file was deleted.

36 changes: 0 additions & 36 deletions packages/app-slide/example/package.json

This file was deleted.

Loading

0 comments on commit fcde603

Please sign in to comment.