Skip to content

Commit

Permalink
fix: codes refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
1ncounter committed Jul 30, 2024
1 parent 006b9b6 commit a02b19e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 38 deletions.
2 changes: 2 additions & 0 deletions TODOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
5. test
6. publish
7. github workflows

lodaes replace
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ export default tseslint.config({
'react-hooks/exhaustive-deps': 'off', // Checks effect dependencies

'no-inner-declarations': 'off',
'no-constant-condition': 'off',
},
});
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@
"prepare": "husky"
},
"devDependencies": {
"@changesets/cli": "^2.27.1",
"@commitlint/cli": "^19.2.1",
"@commitlint/config-conventional": "^19.1.0",
"@changesets/cli": "^2.27.7",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@eslint/js": "^8.57.0",
"@microsoft/api-extractor": "^7.43.0",
"@stylistic/eslint-plugin": "^1.7.0",
"@types/node": "^20.11.30",
"@vanilla-extract/vite-plugin": "^4.0.7",
"@vitejs/plugin-react": "^4.2.1",
"@microsoft/api-extractor": "^7.47.4",
"@stylistic/eslint-plugin": "^1.8.1",
"@types/node": "^22.0.0",
"@vanilla-extract/vite-plugin": "^4.0.13",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"globals": "^15.0.0",
"husky": "^9.0.11",
"jsdom": "^24.1.0",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"rimraf": "^5.0.2",
"typescript": "^5.4.2",
"typescript-eslint": "^7.5.0",
"vite": "^5.2.9",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^4.6.2",
"globals": "^15.8.0",
"husky": "^9.1.3",
"jsdom": "^24.1.1",
"lint-staged": "^15.2.7",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"typescript": "^5.5.4",
"typescript-eslint": "^7.17.0",
"vite": "^5.3.5",
"vitest": "^1.6.0"
},
"engines": {
Expand Down
16 changes: 10 additions & 6 deletions packages/react-renderer/src/api/app.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { createRenderer } from '@alilc/lowcode-renderer-core';
import { type Root, createRoot } from 'react-dom/client';
import { RendererContext, getRenderInstancesByAccessor } from './context';
import { type IRendererContext, RendererContext, getRenderInstancesByAccessor } from './context';
import { ApplicationView, boosts } from '../app';
import { type ReactAppOptions } from './types';

export const createApp = async (options: ReactAppOptions) => {
return createRenderer(async (accessor) => {
const instances = getRenderInstancesByAccessor(accessor);
return createRenderer(async (service) => {
const contextValue: IRendererContext = service.invokeFunction((accessor) => {
return {
options,
...getRenderInstancesByAccessor(accessor),
};
});

instances.boostsManager.extend(boosts.toExpose());
contextValue.boostsManager.extend(boosts.toExpose());

let root: Root | undefined;

return {
async mount(containerOrId) {
if (root) return;

const defaultId = instances.schema.get('config')?.targetRootID ?? 'app';
const defaultId = contextValue.schema.get<string>('config.targetRootID', 'app');
const rootElement = normalizeContainer(containerOrId, defaultId);
const contextValue = { ...instances, options };

root = createRoot(rootElement);
root.render(
Expand Down
23 changes: 16 additions & 7 deletions packages/react-renderer/src/api/component.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
import { createRenderer } from '@alilc/lowcode-renderer-core';
import { FunctionComponent } from 'react';
import { type ComponentTreeRoot } from '@alilc/lowcode-shared';
import { type FunctionComponent } from 'react';
import {
type LowCodeComponentProps,
createComponent as createSchemaComponent,
} from '../runtime/createComponent';
import { RendererContext, getRenderInstancesByAccessor } from './context';
import { type IRendererContext, RendererContext, getRenderInstancesByAccessor } from './context';
import { type ReactAppOptions } from './types';

interface Render {
toComponent(): FunctionComponent<LowCodeComponentProps>;
}

export async function createComponent(options: ReactAppOptions) {
const creator = createRenderer<Render>((accessor) => {
const instances = getRenderInstancesByAccessor(accessor);
const componentsTree = instances.schema.get('componentsTree')[0];
const creator = createRenderer<Render>((service) => {
const contextValue: IRendererContext = service.invokeFunction((accessor) => {
return {
options,
...getRenderInstancesByAccessor(accessor),
};
});

const componentsTree = contextValue.schema.get<ComponentTreeRoot>('componentsTree.0');

if (!componentsTree) {
throw new Error('componentsTree is required');
}

const LowCodeComponent = createSchemaComponent(componentsTree, {
displayName: componentsTree.componentName,
...options.component,
});

const contextValue = { ...instances, options };

function Component(props: LowCodeComponentProps) {
return (
<RendererContext.Provider value={contextValue}>
Expand Down
7 changes: 3 additions & 4 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ const buildTypes = args['types'] || args['t'];
async function run() {
const packages = await findWorkspacePackages(cwd());
const targetPackageName = `@alilc/lowcode-${targets[0]}`;
const finalName = packages
.filter((item) => item.manifest.name === targetPackageName)
.map(item => item.manifest.name);
const manifest = packages.filter((item) => item.manifest.name === targetPackageName)[0].manifest;

await execa('pnpm', ['--filter', finalName[0], 'build:target'], {
await execa('pnpm', ['--filter', manifest.name, 'build:target'], {
stdio: 'inherit',
env: {
PROD: prod,
FORMATS: formatArgs ? formatArgs : !prod ? 'es' : undefined,
VERSION: manifest.version,
},
});

Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"importHelpers": false,
// Enables experimental support for ES7 decorators.
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
// Generates corresponding .map file.
"sourceMap": true,
// Disallow inconsistently-cased references to the same file.
Expand All @@ -37,7 +36,7 @@
"paths": {
"@alilc/lowcode-*": ["packages/*/src"]
},
"types": ["vite/client", "vitest/globals", "node"]
"types": ["vitest/globals", "node"]
},
"include": [
"packages/global.d.ts",
Expand Down
4 changes: 4 additions & 0 deletions vite.base.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export default async ({
}

return defineConfig({
define: {
__DEV__: JSON.stringify(!isProduction),
__VERSION__: JSON.stringify(env['VERSION']),
},
build: {
lib: {
entry: resolvePath(entry),
Expand Down

0 comments on commit a02b19e

Please sign in to comment.