annil 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +8 -2
- package/dist/api/DefineComponent/ReturnType/test/normalComponentDoc.test.js.map +1 -1
- package/dist/api/DefineComponent/ReturnType/test/normalPageDoc.test.js.map +1 -1
- package/dist/api/DefineComponent/index.js +18 -13
- package/dist/api/DefineComponent/index.js.map +1 -1
- package/dist/api/RootComponent/Lifetimes/LifetimesConstraint.d.ts +4 -1
- package/dist/api/RootComponent/Properties/{expected/normalEmpty.js → test/normalEmpty.test.js} +1 -1
- package/dist/api/RootComponent/Properties/test/normalEmpty.test.js.map +1 -0
- package/dist/api/RootComponent/Watch/test/WatchProperties.test.js +1 -1
- package/dist/api/RootComponent/Watch/test/WatchProperties.test.js.map +1 -1
- package/dist/api/SubComponent/SubComputed/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubData/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/SubData/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubInstance/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubWatch/test/WatchRootData.test.js.map +1 -1
- package/dist/api/SubComponent/index.d.ts +1 -1
- package/dist/api/SubComponent/index.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/data-tracer.js +0 -3
- package/dist/behaviors/BComputedAndWatch/data-tracer.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/index.js +2 -1
- package/dist/behaviors/BComputedAndWatch/index.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/initComputed.js +3 -11
- package/dist/behaviors/BComputedAndWatch/initComputed.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/isEqual.js.map +1 -1
- package/dist/behaviors/BStore.js.map +1 -1
- package/dist/behaviors/BbeforeCreated.js.map +1 -1
- package/dist/types/GetComponentPrefix.js +1 -4
- package/dist/types/GetComponentPrefix.js.map +1 -1
- package/dist/types/ReplacePrefix.js +1 -4
- package/dist/types/ReplacePrefix.js.map +1 -1
- package/dist/utils/InternalFieldProtection.d.ts +2 -0
- package/dist/utils/InternalFieldProtection.js +11 -0
- package/dist/utils/InternalFieldProtection.js.map +1 -0
- package/dist/utils/collector.d.ts +5 -0
- package/dist/utils/collector.js +21 -0
- package/dist/utils/collector.js.map +1 -0
- package/dist/utils/createdHijack.d.ts +0 -0
- package/dist/utils/createdHijack.js +2 -0
- package/dist/utils/createdHijack.js.map +1 -0
- package/dist/utils/customEventsHandle.d.ts +2 -0
- package/dist/utils/customEventsHandle.js +20 -0
- package/dist/utils/customEventsHandle.js.map +1 -0
- package/dist/utils/eventsHandle.d.ts +2 -0
- package/dist/utils/eventsHandle.js +5 -0
- package/dist/utils/eventsHandle.js.map +1 -0
- package/dist/utils/funcConfigHandle.d.ts +2 -0
- package/dist/utils/funcConfigHandle.js +18 -0
- package/dist/utils/funcConfigHandle.js.map +1 -0
- package/dist/utils/onLoadHijack.d.ts +3 -0
- package/dist/utils/onLoadHijack.js +16 -0
- package/dist/utils/onLoadHijack.js.map +1 -0
- package/dist/utils/onLoadReceivedDataHandle.d.ts +3 -0
- package/dist/utils/onLoadReceivedDataHandle.js +14 -0
- package/dist/utils/onLoadReceivedDataHandle.js.map +1 -0
- package/dist/utils/rootComponentFieldHandle.d.ts +3 -0
- package/dist/utils/rootComponentFieldHandle.js +13 -0
- package/dist/utils/rootComponentFieldHandle.js.map +1 -0
- package/dist/utils/subComponentsHandle.d.ts +3 -0
- package/dist/utils/subComponentsHandle.js +12 -0
- package/dist/utils/subComponentsHandle.js.map +1 -0
- package/package.json +4 -3
- package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +2 -1
- package/src/api/DefineComponent/ReturnType/test/normalPageDoc.test.ts +2 -1
- package/src/api/DefineComponent/index.ts +27 -22
- package/src/api/RootComponent/Computed/test/normal.test.ts +1 -1
- package/src/api/RootComponent/Lifetimes/LifetimesConstraint.ts +8 -7
- package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +1 -1
- package/src/api/RootComponent/Watch/test/WatchComputed.test.ts +1 -1
- package/src/api/RootComponent/Watch/test/WatchData.test.ts +1 -1
- package/src/api/RootComponent/Watch/test/WatchProperties.test.ts +8 -2
- package/src/api/SubComponent/SubComputed/test/normal.test.ts +2 -1
- package/src/api/SubComponent/SubData/test/error.test.ts +2 -1
- package/src/api/SubComponent/SubData/test/normal.test.ts +2 -1
- package/src/api/SubComponent/SubInstance/test/normal.test.ts +2 -1
- package/src/api/SubComponent/SubPageLifetimes/test/normal.test.ts +2 -1
- package/src/api/SubComponent/SubWatch/test/WatchRootData.test.ts +2 -1
- package/src/api/SubComponent/SubWatch/test/error.test.ts +1 -1
- package/src/api/SubComponent/index.ts +9 -1
- package/src/behaviors/BComputedAndWatch/data-tracer.ts +0 -3
- package/src/behaviors/BComputedAndWatch/index.ts +8 -4
- package/src/behaviors/BComputedAndWatch/initComputed.ts +25 -18
- package/src/behaviors/BComputedAndWatch/isEqual.ts +1 -0
- package/src/behaviors/BStore.ts +3 -1
- package/src/behaviors/BbeforeCreated.ts +3 -1
- package/src/types/GetComponentPrefix.ts +11 -11
- package/src/types/ReplacePrefix.ts +9 -10
- package/src/utils/InternalFieldProtection.ts +18 -0
- package/src/utils/collector.ts +41 -0
- package/src/utils/createdHijack.ts +21 -0
- package/src/utils/customEventsHandle.ts +31 -0
- package/src/utils/eventsHandle.ts +10 -0
- package/src/utils/funcConfigHandle.ts +30 -0
- package/src/utils/onLoadHijack.ts +30 -0
- package/src/utils/onLoadReceivedDataHandle.ts +31 -0
- package/src/utils/rootComponentFieldHandle.ts +27 -0
- package/src/utils/subComponentsHandle.ts +25 -0
- package/dist/api/RootComponent/Data/expected/error.js +0 -10
- package/dist/api/RootComponent/Data/expected/error.js.map +0 -1
- package/dist/api/RootComponent/Data/expected/normal.d.ts +0 -1
- package/dist/api/RootComponent/Data/expected/normal.js +0 -33
- package/dist/api/RootComponent/Data/expected/normal.js.map +0 -1
- package/dist/api/RootComponent/Properties/expected/error.d.ts +0 -1
- package/dist/api/RootComponent/Properties/expected/error.js +0 -38
- package/dist/api/RootComponent/Properties/expected/error.js.map +0 -1
- package/dist/api/RootComponent/Properties/expected/normalEmpty.d.ts +0 -1
- package/dist/api/RootComponent/Properties/expected/normalEmpty.js.map +0 -1
- package/dist/api/RootComponent/Properties/expected/normalOptional.d.ts +0 -1
- package/dist/api/RootComponent/Properties/expected/normalOptional.js +0 -80
- package/dist/api/RootComponent/Properties/expected/normalOptional.js.map +0 -1
- package/dist/api/RootComponent/Properties/expected/normalRequired.d.ts +0 -69
- package/dist/api/RootComponent/Properties/expected/normalRequired.js +0 -44
- package/dist/api/RootComponent/Properties/expected/normalRequired.js.map +0 -1
- package/dist/api/RootComponent/Properties/test/normalEmpty.test..d.ts +0 -1
- package/dist/api/RootComponent/Properties/test/normalEmpty.test..js +0 -20
- package/dist/api/RootComponent/Properties/test/normalEmpty.test..js.map +0 -1
- package/dist/types/RestorePropTypeOfList.d.ts +0 -2
- package/dist/types/RestorePropTypeOfList.js +0 -3
- package/dist/types/RestorePropTypeOfList.js.map +0 -1
- package/dist/utils/preprocessingOptions.d.ts +0 -18
- package/dist/utils/preprocessingOptions.js +0 -184
- package/dist/utils/preprocessingOptions.js.map +0 -1
- package/src/api/RootComponent/Data/expected/error.ts +0 -14
- package/src/api/RootComponent/Data/expected/normal.ts +0 -68
- package/src/api/RootComponent/Properties/expected/error.ts +0 -49
- package/src/api/RootComponent/Properties/expected/normalEmpty.ts +0 -33
- package/src/api/RootComponent/Properties/expected/normalOptional.ts +0 -136
- package/src/api/RootComponent/Properties/expected/normalRequired.ts +0 -100
- package/src/types/RestorePropTypeOfList.ts +0 -20
- package/src/utils/preprocessingOptions.ts +0 -334
- /package/dist/api/RootComponent/{Data/expected/error.d.ts → Properties/test/normalEmpty.test.d.ts} +0 -0
- /package/src/api/RootComponent/Properties/test/{normalEmpty.test..ts → normalEmpty.test.ts} +0 -0
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { comparer, reaction, toJS } from "mobx";
|
|
2
|
-
import { deepClone } from "./deepClone";
|
|
3
|
-
import { INNERMARKER } from "./InnerMarker";
|
|
4
|
-
function IsFullCustomEvents(customEventOptions) {
|
|
5
|
-
return Object.prototype.toString.call(customEventOptions) === "[object Object]";
|
|
6
|
-
}
|
|
7
|
-
function customEventsHandle(componentOptions, customEventsConfig) {
|
|
8
|
-
componentOptions.methods || (componentOptions.methods = {});
|
|
9
|
-
for (const key in customEventsConfig) {
|
|
10
|
-
const customEventOptions = customEventsConfig[key];
|
|
11
|
-
if (IsFullCustomEvents(customEventOptions)) {
|
|
12
|
-
componentOptions.methods[key] = function (detail) {
|
|
13
|
-
this.triggerEvents(key, detail, customEventOptions.options);
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
componentOptions.methods[key] = function (detail) {
|
|
18
|
-
this.triggerEvents(key, detail);
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function eventsHandle(componentOptions, eventsConfig) {
|
|
24
|
-
componentOptions.methods || (componentOptions.methods = {});
|
|
25
|
-
Object.assign(componentOptions.methods, eventsConfig);
|
|
26
|
-
}
|
|
27
|
-
function funcFieldsCollect(config, funcConfig, type) {
|
|
28
|
-
for (const key in config) {
|
|
29
|
-
const handler = config[key];
|
|
30
|
-
const tempCache = funcConfig[type] || (funcConfig[type] = {});
|
|
31
|
-
const filedList = tempCache[key] || (tempCache[key] = []);
|
|
32
|
-
filedList.push(handler);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function otherFieldsHandle(componentOptions, rootComponentOptions) {
|
|
36
|
-
for (const key in rootComponentOptions) {
|
|
37
|
-
const config = rootComponentOptions[key];
|
|
38
|
-
if (Array.isArray(config)) {
|
|
39
|
-
componentOptions[key] || (componentOptions[key] = [].push(...config));
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
Object.assign(componentOptions[key] || (componentOptions[key] = {}), config);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export function rootComponentFieldHandle(rootComponentConfig, componentOptions, funcConfig) {
|
|
47
|
-
rootComponentConfig.customEvents && customEventsHandle(componentOptions, rootComponentConfig.customEvents);
|
|
48
|
-
rootComponentConfig.events && eventsHandle(componentOptions, rootComponentConfig.events);
|
|
49
|
-
rootComponentConfig.pageLifetimes
|
|
50
|
-
&& funcFieldsCollect(rootComponentConfig.pageLifetimes, funcConfig, "pageLifetimes");
|
|
51
|
-
rootComponentConfig.lifetimes && funcFieldsCollect(rootComponentConfig.lifetimes, funcConfig, "lifetimes");
|
|
52
|
-
rootComponentConfig.watch && funcFieldsCollect(rootComponentConfig.watch, funcConfig, "watch");
|
|
53
|
-
otherFieldsHandle(componentOptions, rootComponentConfig);
|
|
54
|
-
}
|
|
55
|
-
export function subComponentsHandle(componentOptions, subComponents, funcConfig) {
|
|
56
|
-
subComponents.forEach((subOption) => {
|
|
57
|
-
subOption.events && eventsHandle(componentOptions, subOption.events);
|
|
58
|
-
subOption.pageLifetimes && funcFieldsCollect(subOption.pageLifetimes, funcConfig, "pageLifetimes");
|
|
59
|
-
subOption.lifetimes && funcFieldsCollect(subOption.lifetimes, funcConfig, "lifetimes");
|
|
60
|
-
subOption.watch && funcFieldsCollect(subOption.watch, funcConfig, "watch");
|
|
61
|
-
otherFieldsHandle(componentOptions, subOption);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
function funcCofnigHandle(methodsConfig, configList) {
|
|
65
|
-
for (const key in configList) {
|
|
66
|
-
methodsConfig[key] = function (...args) {
|
|
67
|
-
configList[key].forEach(ele => ele.call(this, ...args));
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
export function funcConfigHandle(componentOptions, isPage, funcConfig) {
|
|
72
|
-
if (isPage) {
|
|
73
|
-
funcConfig.pageLifetimes && funcCofnigHandle(componentOptions.methods || (componentOptions.methods = {}), funcConfig.pageLifetimes);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
funcConfig.pageLifetimes && funcCofnigHandle(componentOptions.pageLifetimes || (componentOptions.pageLifetimes = {}), funcConfig.pageLifetimes);
|
|
77
|
-
}
|
|
78
|
-
funcConfig.lifetimes && funcCofnigHandle(componentOptions.lifetimes || (componentOptions.lifetimes = {}), funcConfig.lifetimes);
|
|
79
|
-
funcConfig.watch && funcCofnigHandle(componentOptions.watch || (componentOptions.watch = {}), funcConfig.watch);
|
|
80
|
-
}
|
|
81
|
-
export function createdHijack(componentOptions, before = [], after = []) {
|
|
82
|
-
const lifetimes = componentOptions.lifetimes || (componentOptions.lifetimes = {});
|
|
83
|
-
const originalCreatedFn = lifetimes.created;
|
|
84
|
-
lifetimes.created = function () {
|
|
85
|
-
before.forEach((func) => {
|
|
86
|
-
func.call(this, componentOptions);
|
|
87
|
-
});
|
|
88
|
-
originalCreatedFn && originalCreatedFn.call(this);
|
|
89
|
-
after.forEach((func) => {
|
|
90
|
-
func.call(this, componentOptions);
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
export function addComputedFieldToMethods(componentOptions) {
|
|
95
|
-
var _a;
|
|
96
|
-
(_a = componentOptions.methods) !== null && _a !== void 0 ? _a : (componentOptions.methods = {});
|
|
97
|
-
componentOptions.methods.__computedConfig__ = () => componentOptions.computed;
|
|
98
|
-
componentOptions.methods.xxx = () => ({
|
|
99
|
-
a() {
|
|
100
|
-
return 123;
|
|
101
|
-
},
|
|
102
|
-
b: 345,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
export function attachedHijack(componentOptions, beforeHandleList = [], afterHandleList = []) {
|
|
106
|
-
var _a;
|
|
107
|
-
(_a = componentOptions.lifetimes) !== null && _a !== void 0 ? _a : (componentOptions.lifetimes = {});
|
|
108
|
-
const originAttached = componentOptions.lifetimes.attached;
|
|
109
|
-
componentOptions.lifetimes.attached = function () {
|
|
110
|
-
beforeHandleList.forEach(handleFunc => {
|
|
111
|
-
handleFunc.call(this);
|
|
112
|
-
});
|
|
113
|
-
originAttached && originAttached.call(this);
|
|
114
|
-
afterHandleList.forEach(handleFunc => {
|
|
115
|
-
handleFunc.call(this);
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
export function detachedHijack(componentOptions, beforeHandleList = [], afterHandleList = []) {
|
|
120
|
-
var _a;
|
|
121
|
-
(_a = componentOptions.lifetimes) !== null && _a !== void 0 ? _a : (componentOptions.lifetimes = {});
|
|
122
|
-
const originDetached = componentOptions.lifetimes.detached;
|
|
123
|
-
componentOptions.lifetimes.detached = function () {
|
|
124
|
-
beforeHandleList.forEach(handleFunc => {
|
|
125
|
-
handleFunc.call(this);
|
|
126
|
-
});
|
|
127
|
-
originDetached && originDetached.call(this);
|
|
128
|
-
afterHandleList.forEach(handleFunc => {
|
|
129
|
-
handleFunc.call(this);
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
export function storeHandle() {
|
|
134
|
-
var _a;
|
|
135
|
-
const responsiveConfig = (_a = this.__storeConfig__) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
136
|
-
if (!responsiveConfig)
|
|
137
|
-
return;
|
|
138
|
-
for (const key in responsiveConfig) {
|
|
139
|
-
this.disposer || (this.disposer = {});
|
|
140
|
-
this.disposer[key] = reaction(responsiveConfig[key], (value) => {
|
|
141
|
-
this.setData({
|
|
142
|
-
[key]: toJS(value),
|
|
143
|
-
});
|
|
144
|
-
}, {
|
|
145
|
-
equals: comparer.default,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
Reflect.deleteProperty(this.__proto__, "__storeConfig__");
|
|
149
|
-
}
|
|
150
|
-
export function excludeFields(config, excludeKeys) {
|
|
151
|
-
const methodsConfigKeys = Object.keys(config);
|
|
152
|
-
for (const key of excludeKeys) {
|
|
153
|
-
if (methodsConfigKeys.includes(key)) {
|
|
154
|
-
throw Error(`${key}已被内部字段占用`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
export function onLoadHijack(options, before, after = []) {
|
|
159
|
-
options.methods || (options.methods = {});
|
|
160
|
-
const cloneOpt = deepClone(options);
|
|
161
|
-
const originalOnLoad = options.methods.onLoad;
|
|
162
|
-
options.methods.onLoad = function (props) {
|
|
163
|
-
before.forEach((func) => {
|
|
164
|
-
func.call(this, props, cloneOpt);
|
|
165
|
-
});
|
|
166
|
-
originalOnLoad === null || originalOnLoad === void 0 ? void 0 : originalOnLoad.call(this, props);
|
|
167
|
-
after.forEach((func) => {
|
|
168
|
-
func.call(this, props, cloneOpt);
|
|
169
|
-
});
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
export function onLoadReceivedDataHandle(option) {
|
|
173
|
-
const innerData = option[INNERMARKER.url];
|
|
174
|
-
if (innerData === undefined)
|
|
175
|
-
return;
|
|
176
|
-
const optionData = JSON.parse(decodeURIComponent(innerData));
|
|
177
|
-
for (const key in optionData) {
|
|
178
|
-
option[key] = optionData[key];
|
|
179
|
-
}
|
|
180
|
-
this.setData(option);
|
|
181
|
-
delete option[INNERMARKER.url];
|
|
182
|
-
delete this.data[INNERMARKER.url];
|
|
183
|
-
}
|
|
184
|
-
//# sourceMappingURL=preprocessingOptions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preprocessingOptions.js","sourceRoot":"","sources":["../../src/utils/preprocessingOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAQhD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,SAAS,kBAAkB,CACzB,kBAAyD;IAEzD,OAAO,MAAM,CAAC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+0,0 @@
|
|
|
1
|
-
import { Checking, type Test } from "hry-types";
|
|
2
|
-
|
|
3
|
-
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
4
|
-
import { RootComponent } from "../..";
|
|
5
|
-
|
|
6
|
-
const RootDoc = RootComponent()({
|
|
7
|
-
data: {
|
|
8
|
-
gender: <"male" | "female"> "male",
|
|
9
|
-
num: 123,
|
|
10
|
-
_innernalFields: false,
|
|
11
|
-
},
|
|
12
|
-
methods: {
|
|
13
|
-
foo() {
|
|
14
|
-
// 1 this.data 类型检查
|
|
15
|
-
Checking<typeof this.data, ReadonlyDeep<RootDocExpected>, Test.Pass>;
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
type RootDocExpected = {
|
|
21
|
-
gender: "male" | "female";
|
|
22
|
-
num: number;
|
|
23
|
-
_innernalFields: boolean;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// 2 返回文档中的data字段类型检查
|
|
27
|
-
Checking<typeof RootDoc["data"], RootDocExpected, Test.Pass>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* data字段配置为空对象时
|
|
31
|
-
*/
|
|
32
|
-
const EmptyDataRootDoc = RootComponent()({
|
|
33
|
-
data: {},
|
|
34
|
-
methods: {
|
|
35
|
-
M1() {
|
|
36
|
-
// 3 this.data为 `{}`类型
|
|
37
|
-
Checking<typeof this.data, {}, Test.Pass>;
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// 4 返回文档中无data字段
|
|
43
|
-
Checking<typeof EmptyDataRootDoc, { methods: { M1: () => void } }, Test.Pass>;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 无data字段配置时
|
|
47
|
-
*/
|
|
48
|
-
const noDataRootDoc = RootComponent()({
|
|
49
|
-
methods: {
|
|
50
|
-
M1() {
|
|
51
|
-
// 5 data为空对象时 this.data为{}类型
|
|
52
|
-
Checking<typeof this.data, {}, Test.Pass>;
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// 6 返回文档中无data字段
|
|
58
|
-
Checking<typeof noDataRootDoc, { methods: { M1: () => void } }, Test.Pass>;
|
|
59
|
-
|
|
60
|
-
// 1 如果在组件A构建前初始化A组件的计算属性,可以在A组件并入子组件B时传递给组件B计算属性值,但由于A组件的计算属性可能依赖properties字段,所以B组件的watch字段监控的properties(即A传递的计算属性)是无意义的。
|
|
61
|
-
|
|
62
|
-
// 2 如果在created字段初始化A组件的计算属性.与上述一样效果
|
|
63
|
-
|
|
64
|
-
// 3 如果在attached初始化计算属性那么 那么会导致子组件B 接受properties时报警告,因为A组件的计算属性还为生效即为undefined。
|
|
65
|
-
|
|
66
|
-
// 4 watch 的建立时机问题: 一定是在created之前
|
|
67
|
-
|
|
68
|
-
// 问题时watch的建立需要计算属性初始化的数据依赖情况。即properties是否被依赖
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { RootComponent, type SpecificType } from "../../../../index";
|
|
2
|
-
import type { Mock_Cart } from "./normalRequired";
|
|
3
|
-
|
|
4
|
-
// 1 非法字段
|
|
5
|
-
RootComponent()({
|
|
6
|
-
properties: {
|
|
7
|
-
num: {
|
|
8
|
-
type: Number,
|
|
9
|
-
// @ts-expect-error 非法字段 values多了`s`
|
|
10
|
-
values: 123,
|
|
11
|
-
},
|
|
12
|
-
bool: {
|
|
13
|
-
type: Boolean,
|
|
14
|
-
value: true,
|
|
15
|
-
// @ts-expect-error 非法字段 optionalType少了`s`
|
|
16
|
-
optionalType: [String],
|
|
17
|
-
},
|
|
18
|
-
union: {
|
|
19
|
-
type: Number,
|
|
20
|
-
value: 123,
|
|
21
|
-
optionalTypes: [String],
|
|
22
|
-
// @ts-expect-error 非法字段 observable
|
|
23
|
-
observable: "",
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// 2 value 类型错误
|
|
29
|
-
RootComponent()({
|
|
30
|
-
properties: {
|
|
31
|
-
str: {
|
|
32
|
-
type: String,
|
|
33
|
-
// @ts-expect-error 类型错误
|
|
34
|
-
value: 123,
|
|
35
|
-
},
|
|
36
|
-
optionalObj: {
|
|
37
|
-
// @ts-expect-error 可选对象value若写null,需要先定义
|
|
38
|
-
type: Object as SpecificType<Mock_Cart>,
|
|
39
|
-
// @ts-expect-error 可选对象value若写null,需要先定义
|
|
40
|
-
value: null,
|
|
41
|
-
},
|
|
42
|
-
str_num: {
|
|
43
|
-
type: String,
|
|
44
|
-
// @ts-expect-error 类型错误 应该写type字段类型(string)而非optionalTypes中的类型
|
|
45
|
-
value: 123,
|
|
46
|
-
optionalTypes: [Number],
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Checking, type Test } from "hry-types";
|
|
2
|
-
import { RootComponent } from "../..";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Properties配置为`{}`时
|
|
6
|
-
*/
|
|
7
|
-
const emptyObj = RootComponent()({
|
|
8
|
-
properties: {},
|
|
9
|
-
methods: {
|
|
10
|
-
foo() {
|
|
11
|
-
// 1 this.data 为空对象类型
|
|
12
|
-
Checking<typeof this.data, {}, Test.Pass>;
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// 2 返回文档类型无properties字段
|
|
18
|
-
Checking<typeof emptyObj, { methods: { foo: () => void } }, Test.Pass>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 无Properties配置时
|
|
22
|
-
*/
|
|
23
|
-
const noProperties = RootComponent()({
|
|
24
|
-
methods: {
|
|
25
|
-
foo() {
|
|
26
|
-
// 3 this.data 为空对象类型
|
|
27
|
-
Checking<typeof this.data, {}, Test.Pass>;
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// 4 返回文档类型无properties字段
|
|
33
|
-
Checking<typeof noProperties, { methods: { foo(): void } }, Test.Pass>;
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { Checking, type Test } from "hry-types";
|
|
2
|
-
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
3
|
-
import type { SpecificType } from "../../../../types/SpecificType";
|
|
4
|
-
import { RootComponent } from "../..";
|
|
5
|
-
import { type Mock_User } from "./normalRequired";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 1 组件实例 properties字段选传类型配置 类型为[OptionalType](../PropertiesConstraint.ts)
|
|
9
|
-
*/
|
|
10
|
-
const OptionalDoc = RootComponent()({
|
|
11
|
-
properties: {
|
|
12
|
-
optional_num: { // 普通类型
|
|
13
|
-
type: Number,
|
|
14
|
-
value: 123,
|
|
15
|
-
},
|
|
16
|
-
optional_gender: {
|
|
17
|
-
type: String as SpecificType<"male" | "female">, // 同类字面量联合类型
|
|
18
|
-
value: "male",
|
|
19
|
-
},
|
|
20
|
-
optional_tuple: {
|
|
21
|
-
type: Array as unknown as SpecificType<[number, string, boolean]>, // 元组类型
|
|
22
|
-
value: [1, "a", true] as [number, string, boolean],
|
|
23
|
-
},
|
|
24
|
-
optional_obj: {
|
|
25
|
-
type: Object as SpecificType<Mock_User>, // 对象类型
|
|
26
|
-
value: {
|
|
27
|
-
id: "id",
|
|
28
|
-
age: 20,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
optional_objOrNull: {
|
|
32
|
-
type: Object as SpecificType<Mock_User | null>,
|
|
33
|
-
value: null,
|
|
34
|
-
},
|
|
35
|
-
optional_union: { // 非同类联合类型 string | number
|
|
36
|
-
type: String,
|
|
37
|
-
value: "string",
|
|
38
|
-
optionalTypes: [Number],
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
methods: {
|
|
42
|
-
foo() {
|
|
43
|
-
// 2. 内部this.data中的类型(去除可选)
|
|
44
|
-
Checking<
|
|
45
|
-
typeof this.data,
|
|
46
|
-
ReadonlyDeep<{
|
|
47
|
-
optional_num: number;
|
|
48
|
-
optional_gender: "male" | "female";
|
|
49
|
-
optional_tuple: [number, string, boolean];
|
|
50
|
-
optional_obj: Mock_User | null;
|
|
51
|
-
optional_objOrNull: Mock_User | null;
|
|
52
|
-
optional_union: string | number;
|
|
53
|
-
}>,
|
|
54
|
-
Test.Pass
|
|
55
|
-
>;
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
type OptionalDocExpected = {
|
|
61
|
-
// 3. 预期返回类型 key为可选(带`?`)
|
|
62
|
-
|
|
63
|
-
optional_num?: number;
|
|
64
|
-
optional_gender?: "male" | "female";
|
|
65
|
-
optional_tuple?: [number, string, boolean];
|
|
66
|
-
optional_obj?: Mock_User | null;
|
|
67
|
-
optional_objOrNull?: Mock_User | null;
|
|
68
|
-
optional_union?: string | number;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
Checking<typeof OptionalDoc["properties"], OptionalDocExpected, Test.Pass>;
|
|
72
|
-
|
|
73
|
-
// 页面实例 可选对象不加null
|
|
74
|
-
const OptionalDocWhenIsPage = RootComponent()({
|
|
75
|
-
isPage: true,
|
|
76
|
-
properties: {
|
|
77
|
-
optional_num: { // 普通类型
|
|
78
|
-
type: Number,
|
|
79
|
-
value: 123,
|
|
80
|
-
},
|
|
81
|
-
optional_gender: {
|
|
82
|
-
type: String as SpecificType<"male" | "female">, // 同类字面量联合类型
|
|
83
|
-
value: "male",
|
|
84
|
-
},
|
|
85
|
-
optional_tuple: {
|
|
86
|
-
type: Array as unknown as SpecificType<[number, string, boolean]>, // 元组类型
|
|
87
|
-
value: [1, "a", true] as [number, string, boolean],
|
|
88
|
-
},
|
|
89
|
-
optional_obj: {
|
|
90
|
-
type: Object as SpecificType<Mock_User>, // 对象类型
|
|
91
|
-
value: {
|
|
92
|
-
id: "id",
|
|
93
|
-
age: 20,
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
optional_objOrNull: {
|
|
97
|
-
type: Object as SpecificType<Mock_User | null>,
|
|
98
|
-
value: null,
|
|
99
|
-
},
|
|
100
|
-
optional_union: { // 非同类联合类型 string | number
|
|
101
|
-
type: String,
|
|
102
|
-
value: "string",
|
|
103
|
-
optionalTypes: [Number],
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
methods: {
|
|
107
|
-
foo() {
|
|
108
|
-
// 2. 内部this.data中的类型(去除可选)
|
|
109
|
-
Checking<
|
|
110
|
-
typeof this.data,
|
|
111
|
-
ReadonlyDeep<{
|
|
112
|
-
optional_num: number;
|
|
113
|
-
optional_gender: "male" | "female";
|
|
114
|
-
optional_tuple: [number, string, boolean];
|
|
115
|
-
optional_obj: Mock_User; // 不格外添加 Null
|
|
116
|
-
optional_objOrNull: Mock_User | null; // 本身待的null 非格外添加
|
|
117
|
-
optional_union: string | number;
|
|
118
|
-
}>,
|
|
119
|
-
Test.Pass
|
|
120
|
-
>;
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
type OptionalDocWhenIsPageExpected = {
|
|
126
|
-
// 3. 预期返回类型 key为可选(带`?`)
|
|
127
|
-
|
|
128
|
-
optional_num?: number;
|
|
129
|
-
optional_gender?: "male" | "female";
|
|
130
|
-
optional_tuple?: [number, string, boolean];
|
|
131
|
-
optional_obj?: Mock_User; // 不格外添加 Null
|
|
132
|
-
optional_objOrNull?: Mock_User | null; // 本身待的null 非格外添加
|
|
133
|
-
optional_union?: string | number;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
Checking<typeof OptionalDocWhenIsPage["properties"], OptionalDocWhenIsPageExpected, Test.Pass>;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { Checking, type Test } from "hry-types";
|
|
2
|
-
import type { SpecificType } from "../../../../types/SpecificType";
|
|
3
|
-
|
|
4
|
-
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
5
|
-
import { RootComponent } from "../..";
|
|
6
|
-
import type { RequiredSingle, RequiredType, RequiredUnion } from "../PropertiesConstraint";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 公共测试对象类型
|
|
10
|
-
*/
|
|
11
|
-
export type Mock_User = {
|
|
12
|
-
id: string;
|
|
13
|
-
age?: number;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 公共测试对象类型
|
|
18
|
-
*/
|
|
19
|
-
export type Mock_Cart = {
|
|
20
|
-
id: string;
|
|
21
|
-
selectedCount: number;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* properties 必传单一类型配置
|
|
26
|
-
*/
|
|
27
|
-
export const mock_requiredSingle = {
|
|
28
|
-
str: String,
|
|
29
|
-
num: Number,
|
|
30
|
-
bool: Boolean,
|
|
31
|
-
arr: Array,
|
|
32
|
-
obj: Object,
|
|
33
|
-
tuple: Array as unknown as SpecificType<[string, number, boolean]>,
|
|
34
|
-
union_str: String as SpecificType<"male" | "female">,
|
|
35
|
-
union_num: Number as SpecificType<0 | 1 | 2>,
|
|
36
|
-
union_bool: Boolean as SpecificType<false | true>,
|
|
37
|
-
union_arr: Array as SpecificType<number[] | string[]>,
|
|
38
|
-
union_obj: Object as SpecificType<Mock_User | Mock_Cart>,
|
|
39
|
-
} satisfies Record<string, RequiredSingle>;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* properties 必传联合类型配置
|
|
43
|
-
*/
|
|
44
|
-
export const mock_requiredUnion = {
|
|
45
|
-
union_str_num_bool: {
|
|
46
|
-
type: String,
|
|
47
|
-
optionalTypes: [Number, Boolean],
|
|
48
|
-
},
|
|
49
|
-
union_literalStr_Literalnum: {
|
|
50
|
-
type: String as SpecificType<"male" | "female">,
|
|
51
|
-
optionalTypes: [Number as SpecificType<0 | 1 | 2>],
|
|
52
|
-
},
|
|
53
|
-
union_mockUser_num: {
|
|
54
|
-
type: Object as SpecificType<Mock_User>,
|
|
55
|
-
optionalTypes: [Number],
|
|
56
|
-
},
|
|
57
|
-
union_num_mockUser: {
|
|
58
|
-
type: Number,
|
|
59
|
-
optionalTypes: [Object as SpecificType<Mock_User>],
|
|
60
|
-
},
|
|
61
|
-
} satisfies Record<string, RequiredUnion>;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* properties 必传字段全配置(单一类型 + 联合类型)
|
|
65
|
-
*/
|
|
66
|
-
export const mock_requiredTypes = {
|
|
67
|
-
...mock_requiredSingle,
|
|
68
|
-
...mock_requiredUnion,
|
|
69
|
-
} satisfies Record<string, RequiredType>;
|
|
70
|
-
|
|
71
|
-
type RequiredTypeExpected = {
|
|
72
|
-
str: string;
|
|
73
|
-
num: number;
|
|
74
|
-
bool: boolean;
|
|
75
|
-
arr: unknown[];
|
|
76
|
-
obj: object | null;
|
|
77
|
-
tuple: [string, number, boolean];
|
|
78
|
-
union_str: "male" | "female";
|
|
79
|
-
union_num: 0 | 1 | 2;
|
|
80
|
-
union_bool: boolean;
|
|
81
|
-
union_arr: number[] | string[];
|
|
82
|
-
union_obj: Mock_User | Mock_Cart | null;
|
|
83
|
-
union_str_num_bool: string | number | boolean;
|
|
84
|
-
union_literalStr_Literalnum: 0 | 1 | 2 | "male" | "female";
|
|
85
|
-
union_mockUser_num: number | Mock_User | null;
|
|
86
|
-
union_num_mockUser: number | Mock_User | null;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const RequiredDoc = RootComponent()({
|
|
90
|
-
properties: mock_requiredTypes,
|
|
91
|
-
methods: {
|
|
92
|
-
foo() {
|
|
93
|
-
// 1 this.data中的类型(对象类型加null)
|
|
94
|
-
Checking<typeof this.data, ReadonlyDeep<RequiredTypeExpected>, Test.Pass>;
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// 2 properties文档类型中对象类型加入null(与this.data一致)
|
|
100
|
-
Checking<typeof RequiredDoc["properties"], RequiredTypeExpected, Test.Pass>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Checking, type Test } from "hry-types";
|
|
2
|
-
import type { SpecificType } from "./SpecificType";
|
|
3
|
-
|
|
4
|
-
export type ReStorePropTypeOfList<L, R extends unknown[] = []> = L extends [infer Head, ...infer Rest]
|
|
5
|
-
? ReStorePropTypeOfList<Rest, [...R, SpecificType<Head>]>
|
|
6
|
-
: R;
|
|
7
|
-
|
|
8
|
-
type Test1 = ReStorePropTypeOfList<[number, string, { c: boolean }, boolean, string[]]>;
|
|
9
|
-
|
|
10
|
-
type Test1Expect = [
|
|
11
|
-
SpecificType<number>,
|
|
12
|
-
SpecificType<string>,
|
|
13
|
-
SpecificType<{
|
|
14
|
-
c: boolean;
|
|
15
|
-
}>,
|
|
16
|
-
SpecificType<boolean>,
|
|
17
|
-
SpecificType<string[]>,
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
Checking<Test1, Test1Expect, Test.Pass>;
|