Skip to content

Commit d632e7f

Browse files
committed
refactor: render-core
1 parent 8510f99 commit d632e7f

File tree

112 files changed

+2864
-2546
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+2864
-2546
lines changed

.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
git-checks=false
1+
git-checks=false

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,27 @@
2121
"prepare": "husky"
2222
},
2323
"devDependencies": {
24-
"@alilc/build-plugin-lce": "^0.0.5",
25-
"@alilc/lowcode-test-mate": "^1.0.1",
2624
"@changesets/cli": "^2.27.1",
2725
"@commitlint/cli": "^19.2.1",
2826
"@commitlint/config-conventional": "^19.1.0",
2927
"@eslint/js": "^8.57.0",
3028
"@microsoft/api-extractor": "^7.43.0",
3129
"@stylistic/eslint-plugin": "^1.7.0",
3230
"@types/node": "^20.11.30",
33-
"@types/react-router": "5.1.18",
3431
"@vanilla-extract/vite-plugin": "^4.0.7",
3532
"@vitejs/plugin-react": "^4.2.1",
3633
"eslint": "^8.57.0",
3734
"eslint-plugin-react": "^7.34.1",
3835
"eslint-plugin-react-hooks": "^4.6.0",
3936
"globals": "^15.0.0",
4037
"husky": "^9.0.11",
41-
"less": "^4.2.0",
4238
"lint-staged": "^15.2.2",
4339
"prettier": "^3.2.5",
4440
"rimraf": "^5.0.2",
4541
"typescript": "^5.4.2",
4642
"typescript-eslint": "^7.5.0",
4743
"vite": "^5.2.9",
48-
"vitest": "^1.5.0"
44+
"vitest": "^1.6.0"
4945
},
5046
"engines": {
5147
"node": "^18.18.0 || ^20.9.0 || >=21.1.0",

packages/core/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,10 @@
3333
"test:cov": ""
3434
},
3535
"dependencies": {
36-
"@abraham/reflection": "^0.12.0",
3736
"@alilc/lowcode-shared": "workspace:*",
3837
"@alilc/lowcode-types": "workspace:*",
3938
"@alilc/lowcode-utils": "workspace:*",
4039
"@formatjs/intl": "^2.10.1",
41-
"inversify": "^6.0.2",
42-
"inversify-binding-decorators": "^4.0.0",
4340
"lodash-es": "^4.17.21",
4441
"react": "^18.2.0",
4542
"react-dom": "^18.2.0",
Lines changed: 33 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,32 @@
1-
import { get as lodashGet, isPlainObject } from 'lodash-es';
2-
import { createLogger, type PlainObject, invariant } from '@alilc/lowcode-shared';
3-
4-
const logger = createLogger({ level: 'log', bizName: 'config' });
5-
6-
// this default behavior will be different later
7-
const STRICT_PLUGIN_MODE_DEFAULT = true;
8-
9-
interface ConfigurationOptions<Config extends PlainObject, K extends keyof Config = keyof Config> {
10-
strictMode?: boolean;
11-
setterValidator?: (key: K, value: Config[K]) => boolean | string;
12-
}
1+
import { get as lodashGet, isPlainObject, cloneDeep } from 'lodash-es';
2+
import { type PlainObject } from '@alilc/lowcode-shared/src/types';
3+
import { invariant } from '@alilc/lowcode-shared/src/utils';
134

145
export class Configuration<Config extends PlainObject, K extends keyof Config = keyof Config> {
15-
#strictMode = STRICT_PLUGIN_MODE_DEFAULT;
16-
#setterValidator: (key: K, value: Config[K]) => boolean | string = () => true;
6+
private config: Config;
177

18-
#config: Config = {} as Config;
8+
private setterValidator: ((key: K, value: Config[K]) => boolean | string) | undefined;
199

20-
#waits = new Map<
10+
private waits = new Map<
2111
K,
2212
{
2313
once?: boolean;
2414
resolve: (data: any) => void;
2515
}[]
2616
>();
2717

28-
constructor(config: Config, options?: ConfigurationOptions<Config>) {
18+
constructor(config: Config, setterValidator?: (key: K, value: Config[K]) => boolean | string) {
2919
invariant(config, 'config must exist', 'Configuration');
3020

31-
this.#config = config;
21+
this.config = cloneDeep(config);
3222

33-
const { strictMode, setterValidator } = options ?? {};
34-
35-
if (strictMode === false) {
36-
this.#strictMode = false;
37-
}
3823
if (setterValidator) {
3924
invariant(
4025
typeof setterValidator === 'function',
4126
'setterValidator must be a function',
4227
'Configuration',
4328
);
44-
this.#setterValidator = setterValidator;
29+
this.setterValidator = setterValidator;
4530
}
4631
}
4732

@@ -50,38 +35,35 @@ export class Configuration<Config extends PlainObject, K extends keyof Config =
5035
* @param key
5136
*/
5237
has(key: K): boolean {
53-
return this.#config[key] !== undefined;
38+
return this.config[key] !== undefined;
5439
}
55-
5640
/**
5741
* 获取指定 key 的值
5842
* @param key
5943
* @param defaultValue
6044
*/
61-
get(key: K, defaultValue?: any): any {
62-
return lodashGet(this.#config, key, defaultValue);
45+
get<T = any>(key: K, defaultValue?: T): T | undefined {
46+
return lodashGet(this.config, key, defaultValue);
6347
}
64-
6548
/**
6649
* 设置指定 key 的值
6750
* @param key
6851
* @param value
6952
*/
7053
set(key: K, value: any) {
71-
if (this.#strictMode) {
72-
const valid = this.#setterValidator(key, value);
73-
if (valid === false || typeof valid === 'string') {
74-
return logger.warn(
75-
`failed to config ${key.toString()}, only predefined options can be set under strict mode, predefined options: `,
76-
valid ? valid : '',
77-
);
78-
}
54+
if (this.setterValidator) {
55+
const valid = this.setterValidator(key, value);
56+
57+
invariant(
58+
valid === false || typeof valid === 'string',
59+
`failed to config ${key.toString()}, only predefined options can be set under strict mode, predefined options: ${valid ? valid : ''}`,
60+
'Configuration',
61+
);
7962
}
8063

81-
this.#config[key] = value;
64+
this.config[key] = value;
8265
this.notifyGot(key);
8366
}
84-
8567
/**
8668
* 批量设值,set 的对象版本
8769
* @param config
@@ -93,31 +75,29 @@ export class Configuration<Config extends PlainObject, K extends keyof Config =
9375
});
9476
}
9577
}
96-
9778
/**
9879
* 获取指定 key 的值,若此时还未赋值,则等待,若已有值,则直接返回值
9980
* 注:此函数返回 Promise 实例,只会执行(fullfill)一次
10081
* @param key
10182
* @returns
10283
*/
10384
onceGot(key: K) {
104-
const val = this.#config[key];
85+
const val = this.get(key);
10586
if (val !== undefined) {
10687
return Promise.resolve(val);
10788
}
10889
return new Promise((resolve) => {
10990
this.setWait(key, resolve, true);
11091
});
11192
}
112-
11393
/**
11494
* 获取指定 key 的值,函数回调模式,若多次被赋值,回调会被多次调用
11595
* @param key
11696
* @param fn
11797
* @returns
11898
*/
11999
onGot(key: K, fn: (data: Config[K]) => void): () => void {
120-
const val = this.#config[key];
100+
const val = this.config[key];
121101
if (val !== undefined) {
122102
fn(val);
123103
}
@@ -127,8 +107,8 @@ export class Configuration<Config extends PlainObject, K extends keyof Config =
127107
};
128108
}
129109

130-
notifyGot(key: K): void {
131-
let waits = this.#waits.get(key);
110+
private notifyGot(key: K): void {
111+
let waits = this.waits.get(key);
132112
if (!waits) {
133113
return;
134114
}
@@ -141,23 +121,23 @@ export class Configuration<Config extends PlainObject, K extends keyof Config =
141121
}
142122
}
143123
if (waits.length > 0) {
144-
this.#waits.set(key, waits);
124+
this.waits.set(key, waits);
145125
} else {
146-
this.#waits.delete(key);
126+
this.waits.delete(key);
147127
}
148128
}
149129

150-
setWait(key: K, resolve: (data: any) => void, once?: boolean) {
151-
const waits = this.#waits.get(key);
130+
private setWait(key: K, resolve: (data: any) => void, once?: boolean) {
131+
const waits = this.waits.get(key);
152132
if (waits) {
153133
waits.push({ resolve, once });
154134
} else {
155-
this.#waits.set(key, [{ resolve, once }]);
135+
this.waits.set(key, [{ resolve, once }]);
156136
}
157137
}
158138

159-
delWait(key: K, fn: any) {
160-
const waits = this.#waits.get(key);
139+
private delWait(key: K, fn: any) {
140+
const waits = this.waits.get(key);
161141
if (!waits) {
162142
return;
163143
}
@@ -168,7 +148,7 @@ export class Configuration<Config extends PlainObject, K extends keyof Config =
168148
}
169149
}
170150
if (waits.length < 1) {
171-
this.#waits.delete(key);
151+
this.waits.delete(key);
172152
}
173153
}
174154
}

packages/core/src/configuration/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './configuration';
1+
export * from './preference';
22
export * from './hotkey';
33
export * from './intl';
44
export * from './instantiation';

packages/core/src/instantiation/index.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

packages/core/src/intl.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
computed,
44
effect,
55
createLogger,
6+
type Spec,
67
type Signal,
7-
type I18nMap,
88
type ComputedSignal,
99
type PlainObject,
1010
} from '@alilc/lowcode-shared';
@@ -21,8 +21,8 @@ const logger = createLogger({ level: 'warn', bizName: 'globalLocale' });
2121
const STORED_LOCALE_KEY = 'ali-lowcode-config';
2222

2323
export type Locale = string;
24-
export type IntlMessage = I18nMap[Locale];
25-
export type IntlMessageRecord = I18nMap;
24+
export type IntlMessage = Spec.I18nMap[Locale];
25+
export type IntlMessageRecord = Spec.I18nMap;
2626

2727
export class Intl {
2828
#locale: Signal<Locale>;
@@ -34,7 +34,7 @@ export class Intl {
3434
if (defaultLocale) {
3535
defaultLocale = nomarlizeLocale(defaultLocale);
3636
} else {
37-
defaultLocale = initializeLocale();
37+
defaultLocale = 'zh-CN';
3838
}
3939

4040
const messageStore = mapKeys(messages, (_, key) => {
@@ -65,22 +65,6 @@ export class Intl {
6565

6666
setLocale(locale: Locale) {
6767
const nomarlizedLocale = nomarlizeLocale(locale);
68-
69-
try {
70-
// store storage
71-
let config = JSON.parse(localStorage.getItem(STORED_LOCALE_KEY) || '');
72-
73-
if (config && typeof config === 'object') {
74-
config.locale = locale;
75-
} else {
76-
config = { locale };
77-
}
78-
79-
localStorage.setItem(STORED_LOCALE_KEY, JSON.stringify(config));
80-
} catch {
81-
// ignore;
82-
}
83-
8468
this.#locale.value = nomarlizedLocale;
8569
}
8670

packages/core/src/configuration/preference.ts renamed to packages/core/src/preference.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,3 @@ export class Preference {
6161
return !(result === undefined || result === null);
6262
}
6363
}
64-
65-
export const userPreference = new Preference();

packages/core/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"compilerOptions": {
44
"outDir": "dist"
55
},
6-
"include": ["src", "__tests__"]
6+
"include": ["src", "__tests__", "src/configuration.ts"]
77
}

0 commit comments

Comments
 (0)