Merge branch 'feat/rax-simulator' into release/0.9.0

This commit is contained in:
荣彬 2020-07-21 18:57:12 +08:00
commit f7c90584fd
2 changed files with 50 additions and 53 deletions

View File

@ -24,7 +24,7 @@ import {
import VisualDom from '../comp/visualDom';
import AppContext from '../context/appContext';
// import CompWrapper from '../hoc/compWrapper';
import CompWrapper from '../hoc/compWrapper';
const debug = Debug('engine:base');
const DESIGN_MODE = {
@ -85,31 +85,30 @@ export default class BaseEngine extends Component {
console.warn(e);
}
reloadDataSource = () =>
new Promise((resolve, reject) => {
debug('reload data source');
if (!this.__dataHelper) {
this.__showPlaceholder = false;
return resolve();
}
this.__dataHelper
.getInitData()
.then((res) => {
reloadDataSource = () => new Promise((resolve, reject) => {
debug('reload data source');
if (!this.__dataHelper) {
this.__showPlaceholder = false;
if (isEmpty(res)) {
this.forceUpdate();
return resolve();
}
this.setState(res, resolve);
})
.catch((err) => {
if (this.__showPlaceholder) {
return resolve();
}
this.__dataHelper
.getInitData()
.then((res) => {
this.__showPlaceholder = false;
this.forceUpdate();
}
reject(err);
});
});
if (isEmpty(res)) {
this.forceUpdate();
return resolve();
}
this.setState(res, resolve);
})
.catch((err) => {
if (this.__showPlaceholder) {
this.__showPlaceholder = false;
this.forceUpdate();
}
reject(err);
});
});
__setLifeCycleMethods = (method, args) => {
const lifeCycleMethods = getValue(this.props.__schema, 'lifeCycles', {});
@ -125,8 +124,8 @@ export default class BaseEngine extends Component {
__bindCustomMethods = (props = this.props) => {
const { __schema } = props;
const customMethodsList = Object.keys(__schema.methods || {}) || [];
this.__customMethodsList &&
this.__customMethodsList.forEach((item) => {
this.__customMethodsList
&& this.__customMethodsList.forEach((item) => {
if (!customMethodsList.includes(item)) {
delete this[item];
}
@ -216,8 +215,7 @@ export default class BaseEngine extends Component {
}
}
const { __appHelper: appHelper, __components: components = {}, __componentsMap: componentsMap = {} } =
this.props || {};
const { __appHelper: appHelper, __components: components = {}, __componentsMap: componentsMap = {} } = this.props || {};
const { engine } = this.context || {};
if (isJSExpression(schema)) {
return parseExpression(schema, self);
@ -228,9 +226,7 @@ export default class BaseEngine extends Component {
}
if (Array.isArray(schema)) {
if (schema.length === 1) return this.__createVirtualDom(schema[0], self, parentInfo);
return schema.map((item, idx) =>
this.__createVirtualDom(item, self, parentInfo, item && item.__ctx && item.__ctx.lunaKey ? '' : idx),
);
return schema.map((item, idx) => this.__createVirtualDom(item, self, parentInfo, item && item.__ctx && item.__ctx.lunaKey ? '' : idx),);
}
//
@ -290,11 +286,11 @@ export default class BaseEngine extends Component {
// propscontext
const otherProps = isFileSchema(schema)
? {
__schema: schema,
__appHelper: appHelper,
__components: components,
// __componentsMap: componentsMap,
}
__schema: schema,
__appHelper: appHelper,
__components: components,
// __componentsMap: componentsMap,
}
: {};
if (engine && engine.props.designMode) {
otherProps.__designMode = engine.props.designMode;
@ -309,15 +305,16 @@ export default class BaseEngine extends Component {
},
});
// ref
if (acceptsRef(Comp)) {
otherProps.ref = (ref) => {
const refProps = props.ref;
if (refProps && typeof refProps === 'string') {
this[refProps] = ref;
}
engine && engine.props.onCompGetRef(schema, ref);
};
if (!acceptsRef(Comp)) {
Comp = CompWrapper(Comp);
}
otherProps.ref = (ref) => {
const refProps = props.ref;
if (refProps && typeof refProps === 'string') {
this[refProps] = ref;
}
engine && engine.props.onCompGetRef(schema, ref);
};
// scope
if (scopeKey && this.__compScopes[scopeKey]) {
@ -345,12 +342,12 @@ export default class BaseEngine extends Component {
);
}
const renderComp = (props) => engine.createElement(
Comp,
const renderComp = (props) =>
engine.createElement(
Comp,
props,
(!isFileSchema(schema)
&& !!schema.children
&&
(!isFileSchema(schema) &&
!!schema.children &&
this.__createVirtualDom(
isJSExpression(schema.children) ? parseExpression(schema.children, self) : schema.children,
self,
@ -358,8 +355,8 @@ export default class BaseEngine extends Component {
schema,
Comp,
},
)) ||
null,
))
|| null,
);
//
if (engine && [DESIGN_MODE.EXTEND, DESIGN_MODE.BORDER].includes(engine.props.designMode)) {
@ -457,7 +454,7 @@ export default class BaseEngine extends Component {
if (isEmpty(params)) {
return checkProps(this.__createVirtualDom(data, self, { schema, Comp }));
}
return checkProps(function() {
return checkProps(function () {
const args = {};
if (Array.isArray(params) && params.length) {
params.map((item, idx) => {

View File

@ -268,7 +268,7 @@ export function generateI18n(locale = 'zh-CN', messages = {}) {
* @param {*} Comp 需要判断的组件
*/
export function acceptsRef(Comp) {
return !!Comp;
return Comp && Comp.prototype && Comp.prototype.setState;
}
/**