mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-13 23:31:17 +00:00
feat: 🎸 Rax 出码适配数据源引擎的默认 requestHandlers
This commit is contained in:
parent
e4f6654aa7
commit
5f529aeb40
@ -1,3 +1,4 @@
|
|||||||
|
import changeCase from 'change-case';
|
||||||
import { CLASS_DEFINE_CHUNK_NAME, COMMON_CHUNK_NAME } from '../../../const/generator';
|
import { CLASS_DEFINE_CHUNK_NAME, COMMON_CHUNK_NAME } from '../../../const/generator';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -32,6 +33,27 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
|||||||
...pre,
|
...pre,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const dataSourceConfig = isContainerSchema(pre.ir) ? pre.ir.dataSource : null;
|
||||||
|
const dataSourceItems: DataSourceConfig[] = (dataSourceConfig && dataSourceConfig.list) || [];
|
||||||
|
const dataSourceEngineOptions = { runtimeConfig: true };
|
||||||
|
if (dataSourceItems.length > 0) {
|
||||||
|
Object.assign(dataSourceEngineOptions, {
|
||||||
|
requestHandlers: dataSourceItems.reduce(
|
||||||
|
(handlers, ds) =>
|
||||||
|
ds.type in handlers
|
||||||
|
? handlers
|
||||||
|
: {
|
||||||
|
...handlers,
|
||||||
|
[ds.type]: {
|
||||||
|
type: 'JSExpression',
|
||||||
|
value: `require('@ali/lowcode-datasource-engine/handlers/${changeCase.kebabCase(ds.type)}')`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{} as Record<string, CompositeValue>,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
next.chunks.push({
|
next.chunks.push({
|
||||||
type: ChunkType.STRING,
|
type: ChunkType.STRING,
|
||||||
fileType: FileType.JSX,
|
fileType: FileType.JSX,
|
||||||
@ -47,8 +69,12 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
|||||||
fileType: cfg.fileType,
|
fileType: cfg.fileType,
|
||||||
name: CLASS_DEFINE_CHUNK_NAME.InsVar,
|
name: CLASS_DEFINE_CHUNK_NAME.InsVar,
|
||||||
content: `
|
content: `
|
||||||
_dataSourceConfig = this._defineDataSourceConfig();
|
_dataSourceConfig = this._defineDataSourceConfig();
|
||||||
_dataSourceEngine = __$$createDataSourceEngine(this._dataSourceConfig, this._context, { runtimeConfig: true });`,
|
_dataSourceEngine = __$$createDataSourceEngine(
|
||||||
|
this._dataSourceConfig,
|
||||||
|
this._context,
|
||||||
|
${generateUnknownType(dataSourceEngineOptions)}
|
||||||
|
);`,
|
||||||
linkAfter: [CLASS_DEFINE_CHUNK_NAME.Start],
|
linkAfter: [CLASS_DEFINE_CHUNK_NAME.Start],
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -62,9 +88,6 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
|||||||
linkAfter: [RAX_CHUNK_NAME.ClassDidMountBegin],
|
linkAfter: [RAX_CHUNK_NAME.ClassDidMountBegin],
|
||||||
});
|
});
|
||||||
|
|
||||||
const dataSourceConfig = isContainerSchema(pre.ir) ? pre.ir.dataSource : null;
|
|
||||||
const dataSourceItems: DataSourceConfig[] = (dataSourceConfig && dataSourceConfig.list) || [];
|
|
||||||
|
|
||||||
next.chunks.push({
|
next.chunks.push({
|
||||||
type: ChunkType.STRING,
|
type: ChunkType.STRING,
|
||||||
fileType: cfg.fileType,
|
fileType: cfg.fileType,
|
||||||
|
|||||||
@ -39,7 +39,13 @@ class Home$$Page extends Component {
|
|||||||
_context = this._createContext();
|
_context = this._createContext();
|
||||||
|
|
||||||
_dataSourceConfig = this._defineDataSourceConfig();
|
_dataSourceConfig = this._defineDataSourceConfig();
|
||||||
_dataSourceEngine = __$$createDataSourceEngine(this._dataSourceConfig, this._context, { runtimeConfig: true });
|
_dataSourceEngine = __$$createDataSourceEngine(this._dataSourceConfig, this._context, {
|
||||||
|
runtimeConfig: true,
|
||||||
|
requestHandlers: {
|
||||||
|
urlParams: require('@ali/lowcode-datasource-engine/handlers/url-params'),
|
||||||
|
fetch: require('@ali/lowcode-datasource-engine/handlers/fetch'),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
_utils = this._defineUtils();
|
_utils = this._defineUtils();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user