mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 01:21:58 +00:00
fix: 🐛 schema 中没有 state 的定义, 出码后的 Rax/React 组件应有个默认的空的 state
This commit is contained in:
parent
c8cde85201
commit
7e37f8dd16
@ -32,33 +32,31 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
const ir = next.ir as IContainerInfo;
|
||||
const scope = Scope.createRootScope();
|
||||
|
||||
if (ir.state) {
|
||||
const state = ir.state;
|
||||
const fields = Object.keys(state).map<string>((stateName) => {
|
||||
// TODO: 这里用什么 handlers?
|
||||
const value = generateCompositeType(state[stateName], scope);
|
||||
return `${stateName}: ${value}`;
|
||||
});
|
||||
const state = ir.state || {};
|
||||
const fields = Object.keys(state).map<string>((stateName) => {
|
||||
// TODO: 这里用什么 handlers?
|
||||
const value = generateCompositeType(state[stateName], scope);
|
||||
return `${stateName}: ${value}`;
|
||||
});
|
||||
|
||||
if (cfg.implementType === 'inConstructor') {
|
||||
next.chunks.push({
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
|
||||
content: `this.state = { ${fields.join(',')} };`,
|
||||
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.ConstructorContent]],
|
||||
});
|
||||
} else if (cfg.implementType === 'insMember') {
|
||||
next.chunks.push({
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.InsVar,
|
||||
content: `state = { ${fields.join(',')} };`,
|
||||
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsVar]],
|
||||
});
|
||||
}
|
||||
// TODO: hooks state??
|
||||
if (cfg.implementType === 'inConstructor') {
|
||||
next.chunks.push({
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
|
||||
content: `this.state = { ${fields.join(',')} };`,
|
||||
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.ConstructorContent]],
|
||||
});
|
||||
} else if (cfg.implementType === 'insMember') {
|
||||
next.chunks.push({
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.InsVar,
|
||||
content: `state = { ${fields.join(',')} };`,
|
||||
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsVar]],
|
||||
});
|
||||
}
|
||||
// TODO: hooks state??
|
||||
|
||||
return next;
|
||||
};
|
||||
|
||||
@ -32,32 +32,29 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
const ir = next.ir as IContainerInfo;
|
||||
const scope = Scope.createRootScope();
|
||||
|
||||
if (ir.state) {
|
||||
const { state } = ir;
|
||||
const fields = Object.keys(state).map<string>((stateName) => {
|
||||
const value = generateCompositeType(state[stateName], scope);
|
||||
return `${stateName}: ${value},`;
|
||||
const state = ir.state || {};
|
||||
const fields = Object.keys(state).map<string>((stateName) => {
|
||||
const value = generateCompositeType(state[stateName], scope);
|
||||
return `${stateName}: ${value},`;
|
||||
});
|
||||
|
||||
if (cfg.implementType === 'inConstructor') {
|
||||
next.chunks.push({
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
|
||||
content: `this.state = { ${fields.join('')} };`,
|
||||
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.ConstructorContent]],
|
||||
});
|
||||
} else if (cfg.implementType === 'insMember') {
|
||||
next.chunks.push({
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.InsVar,
|
||||
content: `state = { ${fields.join('')} };`,
|
||||
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsVar]],
|
||||
});
|
||||
|
||||
if (cfg.implementType === 'inConstructor') {
|
||||
next.chunks.push({
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
|
||||
content: `this.state = { ${fields.join('')} };`,
|
||||
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.ConstructorContent]],
|
||||
});
|
||||
} else if (cfg.implementType === 'insMember') {
|
||||
next.chunks.push({
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.InsVar,
|
||||
content: `state = { ${fields.join('')} };`,
|
||||
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.InsVar]],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return next;
|
||||
};
|
||||
return plugin;
|
||||
|
||||
@ -20,6 +20,8 @@ import __$$projectUtils from '../../utils';
|
||||
import './index.css';
|
||||
|
||||
class Home$$Page extends Component {
|
||||
state = {};
|
||||
|
||||
_methods = this._defineMethods();
|
||||
|
||||
_context = this._createContext();
|
||||
|
||||
@ -20,6 +20,8 @@ import __$$projectUtils from '../../utils';
|
||||
import './index.css';
|
||||
|
||||
class Home$$Page extends Component {
|
||||
state = {};
|
||||
|
||||
_methods = this._defineMethods();
|
||||
|
||||
_context = this._createContext();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user