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,8 +85,7 @@ 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; this.__showPlaceholder = false;
@ -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),
);
} }
// //
@ -309,7 +305,9 @@ export default class BaseEngine extends Component {
}, },
}); });
// ref // ref
if (acceptsRef(Comp)) { if (!acceptsRef(Comp)) {
Comp = CompWrapper(Comp);
}
otherProps.ref = (ref) => { otherProps.ref = (ref) => {
const refProps = props.ref; const refProps = props.ref;
if (refProps && typeof refProps === 'string') { if (refProps && typeof refProps === 'string') {
@ -317,7 +315,6 @@ export default class BaseEngine extends Component {
} }
engine && engine.props.onCompGetRef(schema, 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) =>
engine.createElement(
Comp, 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)) {

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;
} }
/** /**