UNPKG

@ray-core/runtime

Version:

Ray 是一个全新的基于 React 的小程序开发框架

49 lines (48 loc) 1.55 kB
import * as React from 'react'; import { RuntimeOptions, ComponentInstanceContext } from '@ray-core/framework-shared'; import Container from './Container'; import render from './render'; // todo 待验证 export default function toNativeComponentConfigCreator(Component, name) { var config = { name: name, data: { action: {}, root: { children: [], }, }, didMount: function () { if (!this.container) { this.init(); } }, didUpdate: function (prevProps, prevData) { if (prevData !== this.data) { return; } this.render(); }, didUnmount: function () { this.container.clearUpdate(); render(null, this.container); }, methods: { init: function () { this.component = RuntimeOptions.get('pluginDriver').onMiniComponent({ component: Component, context: this, }); this.container = new Container(this); this.container.root.type = 'component-root'; this.render(); }, render: function () { this.element = render(React.createElement(ComponentInstanceContext.Provider, { value: this, }, React.createElement(this.component, this.props)), this.container); }, }, }; return config; }