Skip to content

Commit

Permalink
fix: 修复
Browse files Browse the repository at this point in the history
- 修复instanceConfig为undefined的错误
- 其他

type: 新增

- beforeCreate周期函数this为void
- watch字段添加注入数据的类型
  • Loading branch information
missannil committed Dec 19, 2023
1 parent 2e384db commit 4a63e10
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const config = {
"./src/**/*.ts",
"!src/**/*.test.ts",
"!src/api/navigateTo.ts",
"!src/inject.ts",
"!src/api/InstanceInject/inject.ts",
"!src/thirdLib/**",
],
testMatch: [
Expand Down
2 changes: 1 addition & 1 deletion src/api/DefineComponent/collectOptionsForComponent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Func } from "hry-types/src/Misc/_api";
import { instanceConfig } from "../..";
import { BBeforeCreate } from "../../behaviors/BbeforeCreated";
import { BComputedAndWatch } from "../../behaviors/BComputedAndWatch";
import type { ComputedCache, Instance } from "../../behaviors/BComputedAndWatch/types";
Expand All @@ -8,6 +7,7 @@ import { Assign } from "../../types/Assign";
import type { WMComponent } from "../../types/OfficialTypeAlias";
import { INNERMARKER } from "../../utils/InnerMarker";
import { isEmptyObject } from "../../utils/isEmptyObject";
import { instanceConfig } from "../InstanceInject/instanceConfig";
import type { RootComponentTrueOptions } from "../RootComponent";
import type { ComputedConstraint } from "../RootComponent/Computed/ComputedConstraint";
import type {
Expand Down
2 changes: 1 addition & 1 deletion src/inject.ts → src/api/InstanceInject/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const store = {
};

// 声明注入类型 js开发可以忽略
declare module "./index" {
declare module "../.." {
interface IInjectInfo {
data: typeof data;
store: typeof store;
Expand Down
2 changes: 1 addition & 1 deletion src/api/RootComponent/Lifetimes/LifetimesConstraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export type LifetimesConstraint = // 官方组件生命周期
/**
* 建立组件时的真正配置对象
*/
beforeCreate?: (options: FinalOptionsOfComponent) => void;
beforeCreate?: (this: void, options: FinalOptionsOfComponent) => void;
}
>;
3 changes: 3 additions & 0 deletions src/api/RootComponent/Lifetimes/test/normal.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Checking, Test } from "hry-types";
import { RootComponent } from "../../../..";

/**
Expand All @@ -7,6 +8,8 @@ RootComponent()({
lifetimes: {
// 新增声明周期可用于查看或拓展配置文件
beforeCreate(opitons) {
Checking<typeof this, void, Test.Pass>;

opitons;
},
created() {
Expand Down
20 changes: 20 additions & 0 deletions src/api/RootComponent/Watch/test/WtachInject.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Checking, Test } from "hry-types";
import { RootComponent } from "../..";

/**
* watch data字段 深度只读
*/
RootComponent()({
watch: {
injectStr(newValue, oldValue) {
Checking<string, typeof newValue, Test.Pass>;

Checking<string, typeof oldValue, Test.Pass>;
},
injectTheme(newValue, oldValue) {
Checking<"dark" | "light" | undefined, typeof newValue, Test.Pass>;

Checking<"dark" | "light" | undefined, typeof oldValue, Test.Pass>;
},
},
});
2 changes: 2 additions & 0 deletions src/api/RootComponent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ComputeIntersection } from "hry-types/src/Object/_api";
import type { ComputeObject } from "../../types/ComputeObj";
import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
import type { ComponentDoc } from "../DefineComponent/ReturnType/ComponentDoc";
import { IInjectData } from "../InstanceInject/instanceConfig";
import type { ComputedConstraint } from "./Computed/ComputedConstraint";
import type { ComputedOption } from "./Computed/ComputedOption";
import type { GetComputedDoc } from "./Computed/GetComputedDoc";
Expand Down Expand Up @@ -61,6 +62,7 @@ type RootComponentOptions<
& Required<PropertiesDoc>
& DataDoc
& StoreDoc
& IInjectData
>
& Partial<Omit<WMCompOtherOption, "pageLifetimes">>
& ThisType<
Expand Down
3 changes: 1 addition & 2 deletions src/api/SubComponent/SubWatch/SubWatchOption.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { NoInfer } from "hry-types/src/Generic/NoInfer";
import type { WatchOption } from "../../RootComponent/Watch/WatchOption";

export type SubWatchOption<TWatchData extends object> = WatchOption<NoInfer<TWatchData>>;
export type SubWatchOption<TWatchData extends object> = WatchOption<TWatchData>;
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export {
type GenerateDoc,
type IInjectInfo,
instanceConfig,
/* istanbul ignore next */
navigateTo,
type ParamsEqual,
RootComponent,
Expand Down

0 comments on commit 4a63e10

Please sign in to comment.