feat: rax render

This commit is contained in:
响指 2020-07-21 22:47:03 +08:00
parent a42f7cc5fe
commit 038d74e955
5 changed files with 20 additions and 15 deletions

View File

@ -61,5 +61,6 @@
"publishConfig": { "publishConfig": {
"registry": "https://registry.npm.alibaba-inc.com" "registry": "https://registry.npm.alibaba-inc.com"
}, },
"license": "MIT" "license": "MIT",
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-rax-renderer@0.1.2/build/index.html"
} }

View File

@ -1,8 +1,8 @@
/* eslint-disable */ /* eslint-disable */
import { Component, createElement as raxCreateElement } from 'rax'; import { Component, createElement } from 'rax';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Debug from 'debug'; import Debug from 'debug';
import * as isEmpty from 'lodash/isEmpty'; import isEmpty from 'lodash/isEmpty';
import findDOMNode from 'rax-find-dom-node'; import findDOMNode from 'rax-find-dom-node';
import { isFileSchema, goldlog } from '../utils'; import { isFileSchema, goldlog } from '../utils';
import AppContext from '../context/appContext'; import AppContext from '../context/appContext';
@ -21,6 +21,8 @@ const ENGINE_COMPS = {
TempEngine, TempEngine,
}; };
const raxCreateElement = createElement;
class FaultComponent extends Component { class FaultComponent extends Component {
render() { render() {
// FIXME: errorlog // FIXME: errorlog
@ -169,9 +171,10 @@ export default class Engine extends Component {
Comp = ENGINE_COMPS[`${componentName}Engine`]; Comp = ENGINE_COMPS[`${componentName}Engine`];
} }
} }
if (Comp) {
return ( return (
<AppContext.Provider Comp
? <AppContext.Provider
value={{ value={{
appHelper, appHelper,
components: allComponents, components: allComponents,
@ -189,10 +192,9 @@ export default class Engine extends Component {
{...this.props} {...this.props}
/> />
</AppContext.Provider> </AppContext.Provider>
: null
); );
} }
return null;
}
} }
Engine.findDOMNode = findDOMNode; Engine.findDOMNode = findDOMNode;

View File

@ -8,6 +8,7 @@
"license": "MIT", "license": "MIT",
"files": [], "files": [],
"scripts": { "scripts": {
"build": "build-scripts build",
"cloud-build": "build-scripts build --skip-demo", "cloud-build": "build-scripts build --skip-demo",
"test": "ava", "test": "ava",
"test:snapshot": "ava --update-snapshots" "test:snapshot": "ava --update-snapshots"

View File

@ -1,6 +1,7 @@
import { Fragment, Component, createElement } from 'rax'; import { Fragment, Component, createElement } from 'rax';
// import { observer } from './obx-rax/observer'; // import { observer } from './obx-rax/observer';
import RaxEngine from '@ali/lowcode-rax-renderer'; // import RaxEngine from '@ali/lowcode-rax-renderer/lib/index';
import RaxEngine from '../../rax-render/lib/index';
import { SimulatorRenderer } from './renderer'; import { SimulatorRenderer } from './renderer';
import { host } from './host'; import { host } from './host';

View File

@ -393,20 +393,20 @@ function matcher(parent: any) {
function getNodeInstance(dom: HTMLElement): NodeInstance<any> | null { function getNodeInstance(dom: HTMLElement): NodeInstance<any> | null {
const INTERNAL = '_internal'; const INTERNAL = '_internal';
let instance = Instance.get(dom); let instance = Instance.get(dom);
let parent; let node;
while (instance && instance[INTERNAL]) { while (instance && instance[INTERNAL]) {
if (matcher(instance)) { if (matcher(instance)) {
parent = instance; node = instance;
break; break;
} }
instance = instance[INTERNAL].__parentInstance; instance = instance[INTERNAL].__parentInstance;
} }
if (!parent) { if (!node) {
return null; return null;
} }
return { return {
nodeId: parent.props.componentId, nodeId: node.props.componentId,
instance: parent instance: node
} }
// return parent; // return parent;
// const instance = fiberNode.stateNode; // const instance = fiberNode.stateNode;