feat: live mode lifeCycles

This commit is contained in:
wanying.jwy 2020-08-19 23:27:11 +08:00
parent ab66fd4ca5
commit 66f0c79dec
3 changed files with 37 additions and 3 deletions

View File

@ -19,7 +19,7 @@ export function deepValueParser(obj?: any): any {
}
// 兼容 ListSetter 中的变量结构
if (isVariable(obj)) {
if (editor.get('designMode') === 'live'){
if (editor.get('designMode') === 'live') {
return {
type: 'JSExpression',
value: obj.variable,

View File

@ -138,11 +138,23 @@ designer.addPropsReducer((props, node) => {
}, TransformStage.Init);
designer.addPropsReducer((props: any, node: Node) => {
// live 模式下解析 lifeCycles
if (node.isRoot() && props && props.lifeCycles) {
if (editor.get('designMode') === 'live') {
const lifeCycleMap = {
didMount: 'componentDidMount',
willUnmount: 'componentWillUnMount',
};
const lifeCycles = props.lifeCycles;
Object.keys(lifeCycleMap).forEach(key => {
lifeCycles[lifeCycleMap[key]] = lifeCycles[key];
});
return props;
}
return {
...props,
lifeCycles: {},
}
};
}
return props;
}, TransformStage.Render);
@ -220,6 +232,29 @@ designer.addPropsReducer((props: any, node: Node) => {
return props;
}, TransformStage.Save);
// designer.addPropsReducer((props: any, node: Node) => {
// const lifeCycleNames = ['didMount', 'willUnmount'];
// const lifeCycleMap = {
// didMount: 'componentDidMount',
// willUnmount: 'componentWillUnMount',
// };
// if (node.componentName === 'Page') {
// debugger;
// lifeCycleNames.forEach(key => {
// if (props[key]) {
// const lifeCycles = node.props.getPropValue(getConvertedExtraKey('lifeCycles')) || {};
// lifeCycles[lifeCycleMap[key]] = props[key];
// node.props.setPropValue(getConvertedExtraKey('lifeCycles'), lifeCycles);
// } else if (node.props.getPropValue(getConvertedExtraKey('lifeCycles'))) {
// const lifeCycles = node.props.getPropValue(getConvertedExtraKey('lifeCycles')) || {};
// lifeCycles[lifeCycleMap[key]] = lifeCycles[key];
// node.props.setPropValue(getConvertedExtraKey('lifeCycles'), lifeCycles);
// }
// });
// }
// return props;
// }, TransformStage.Init);
// 设计器组件样式处理
function stylePropsReducer(props: any, node: any) {
if (props && typeof props === 'object' && props.__style__) {

View File

@ -22,7 +22,6 @@ export default class PageEngine extends BaseEngine {
static contextType = AppContext;
static getDerivedStateFromProps(props, state) {
debugger;
debug('page.getDerivedStateFromProps');
const func = props.__schema.lifeCycles && props.__schema.lifeCycles.getDerivedStateFromProps;
if (func) {