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

View File

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