Skip to content

Commit a02b19e

Browse files
committed
fix: codes refactor
1 parent 006b9b6 commit a02b19e

File tree

8 files changed

+56
-38
lines changed

8 files changed

+56
-38
lines changed

TODOS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
5. test
1111
6. publish
1212
7. github workflows
13+
14+
lodaes replace

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ export default tseslint.config({
6464
'react-hooks/exhaustive-deps': 'off', // Checks effect dependencies
6565

6666
'no-inner-declarations': 'off',
67+
'no-constant-condition': 'off',
6768
},
6869
});

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@
2020
"prepare": "husky"
2121
},
2222
"devDependencies": {
23-
"@changesets/cli": "^2.27.1",
24-
"@commitlint/cli": "^19.2.1",
25-
"@commitlint/config-conventional": "^19.1.0",
23+
"@changesets/cli": "^2.27.7",
24+
"@commitlint/cli": "^19.3.0",
25+
"@commitlint/config-conventional": "^19.2.2",
2626
"@eslint/js": "^8.57.0",
27-
"@microsoft/api-extractor": "^7.43.0",
28-
"@stylistic/eslint-plugin": "^1.7.0",
29-
"@types/node": "^20.11.30",
30-
"@vanilla-extract/vite-plugin": "^4.0.7",
31-
"@vitejs/plugin-react": "^4.2.1",
27+
"@microsoft/api-extractor": "^7.47.4",
28+
"@stylistic/eslint-plugin": "^1.8.1",
29+
"@types/node": "^22.0.0",
30+
"@vanilla-extract/vite-plugin": "^4.0.13",
31+
"@vitejs/plugin-react": "^4.3.1",
3232
"eslint": "^8.57.0",
33-
"eslint-plugin-react": "^7.34.1",
34-
"eslint-plugin-react-hooks": "^4.6.0",
35-
"globals": "^15.0.0",
36-
"husky": "^9.0.11",
37-
"jsdom": "^24.1.0",
38-
"lint-staged": "^15.2.2",
39-
"prettier": "^3.2.5",
40-
"rimraf": "^5.0.2",
41-
"typescript": "^5.4.2",
42-
"typescript-eslint": "^7.5.0",
43-
"vite": "^5.2.9",
33+
"eslint-plugin-react": "^7.35.0",
34+
"eslint-plugin-react-hooks": "^4.6.2",
35+
"globals": "^15.8.0",
36+
"husky": "^9.1.3",
37+
"jsdom": "^24.1.1",
38+
"lint-staged": "^15.2.7",
39+
"prettier": "^3.3.3",
40+
"rimraf": "^6.0.1",
41+
"typescript": "^5.5.4",
42+
"typescript-eslint": "^7.17.0",
43+
"vite": "^5.3.5",
4444
"vitest": "^1.6.0"
4545
},
4646
"engines": {

packages/react-renderer/src/api/app.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
import { createRenderer } from '@alilc/lowcode-renderer-core';
22
import { type Root, createRoot } from 'react-dom/client';
3-
import { RendererContext, getRenderInstancesByAccessor } from './context';
3+
import { type IRendererContext, RendererContext, getRenderInstancesByAccessor } from './context';
44
import { ApplicationView, boosts } from '../app';
55
import { type ReactAppOptions } from './types';
66

77
export const createApp = async (options: ReactAppOptions) => {
8-
return createRenderer(async (accessor) => {
9-
const instances = getRenderInstancesByAccessor(accessor);
8+
return createRenderer(async (service) => {
9+
const contextValue: IRendererContext = service.invokeFunction((accessor) => {
10+
return {
11+
options,
12+
...getRenderInstancesByAccessor(accessor),
13+
};
14+
});
1015

11-
instances.boostsManager.extend(boosts.toExpose());
16+
contextValue.boostsManager.extend(boosts.toExpose());
1217

1318
let root: Root | undefined;
1419

1520
return {
1621
async mount(containerOrId) {
1722
if (root) return;
1823

19-
const defaultId = instances.schema.get('config')?.targetRootID ?? 'app';
24+
const defaultId = contextValue.schema.get<string>('config.targetRootID', 'app');
2025
const rootElement = normalizeContainer(containerOrId, defaultId);
21-
const contextValue = { ...instances, options };
2226

2327
root = createRoot(rootElement);
2428
root.render(

packages/react-renderer/src/api/component.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
import { createRenderer } from '@alilc/lowcode-renderer-core';
2-
import { FunctionComponent } from 'react';
2+
import { type ComponentTreeRoot } from '@alilc/lowcode-shared';
3+
import { type FunctionComponent } from 'react';
34
import {
45
type LowCodeComponentProps,
56
createComponent as createSchemaComponent,
67
} from '../runtime/createComponent';
7-
import { RendererContext, getRenderInstancesByAccessor } from './context';
8+
import { type IRendererContext, RendererContext, getRenderInstancesByAccessor } from './context';
89
import { type ReactAppOptions } from './types';
910

1011
interface Render {
1112
toComponent(): FunctionComponent<LowCodeComponentProps>;
1213
}
1314

1415
export async function createComponent(options: ReactAppOptions) {
15-
const creator = createRenderer<Render>((accessor) => {
16-
const instances = getRenderInstancesByAccessor(accessor);
17-
const componentsTree = instances.schema.get('componentsTree')[0];
16+
const creator = createRenderer<Render>((service) => {
17+
const contextValue: IRendererContext = service.invokeFunction((accessor) => {
18+
return {
19+
options,
20+
...getRenderInstancesByAccessor(accessor),
21+
};
22+
});
23+
24+
const componentsTree = contextValue.schema.get<ComponentTreeRoot>('componentsTree.0');
25+
26+
if (!componentsTree) {
27+
throw new Error('componentsTree is required');
28+
}
1829

1930
const LowCodeComponent = createSchemaComponent(componentsTree, {
2031
displayName: componentsTree.componentName,
2132
...options.component,
2233
});
2334

24-
const contextValue = { ...instances, options };
25-
2635
function Component(props: LowCodeComponentProps) {
2736
return (
2837
<RendererContext.Provider value={contextValue}>

scripts/build.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ const buildTypes = args['types'] || args['t'];
1212
async function run() {
1313
const packages = await findWorkspacePackages(cwd());
1414
const targetPackageName = `@alilc/lowcode-${targets[0]}`;
15-
const finalName = packages
16-
.filter((item) => item.manifest.name === targetPackageName)
17-
.map(item => item.manifest.name);
15+
const manifest = packages.filter((item) => item.manifest.name === targetPackageName)[0].manifest;
1816

19-
await execa('pnpm', ['--filter', finalName[0], 'build:target'], {
17+
await execa('pnpm', ['--filter', manifest.name, 'build:target'], {
2018
stdio: 'inherit',
2119
env: {
2220
PROD: prod,
2321
FORMATS: formatArgs ? formatArgs : !prod ? 'es' : undefined,
22+
VERSION: manifest.version,
2423
},
2524
});
2625

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"importHelpers": false,
2121
// Enables experimental support for ES7 decorators.
2222
"experimentalDecorators": true,
23-
"emitDecoratorMetadata": true,
2423
// Generates corresponding .map file.
2524
"sourceMap": true,
2625
// Disallow inconsistently-cased references to the same file.
@@ -37,7 +36,7 @@
3736
"paths": {
3837
"@alilc/lowcode-*": ["packages/*/src"]
3938
},
40-
"types": ["vite/client", "vitest/globals", "node"]
39+
"types": ["vitest/globals", "node"]
4140
},
4241
"include": [
4342
"packages/global.d.ts",

vite.base.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export default async ({
3232
}
3333

3434
return defineConfig({
35+
define: {
36+
__DEV__: JSON.stringify(!isProduction),
37+
__VERSION__: JSON.stringify(env['VERSION']),
38+
},
3539
build: {
3640
lib: {
3741
entry: resolvePath(entry),

0 commit comments

Comments
 (0)