UNPKG

@ray-core/runtime

Version:

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

133 lines (132 loc) 5.61 kB
import * as scheduler from 'scheduler'; import { TYPE_TEXT } from '../constants'; import VNode, { processProps } from '../VNode'; import diffProperties from './diffProperties'; import { gStore } from '../gStore'; var scheduleDeferredCallback = scheduler.unstable_scheduleCallback, cancelDeferredCallback = scheduler.unstable_cancelCallback, shouldYield = scheduler.unstable_shouldYield, now = scheduler.unstable_now; var rootHostContext = {}; var childHostContext = {}; export default { now: now, getPublicInstance: function (inst) { // console.log('>>>>>> host config getPublicInstance <<<<<<') return inst; }, getRootHostContext: function () { // console.log('>>>>>> host config getRootHostContext <<<<<<') return rootHostContext; }, shouldSetTextContent: function (type) { // console.log('>>>>>> host config shouldSetTextContent <<<<<<') return type === 'stub-block'; }, prepareForCommit: function () { // console.log('>>>>>> host config prepareForCommit <<<<<<') return null; }, preparePortalMount: function () { }, clearContainer: function () { }, resetAfterCommit: function (container) { // console.log('>>>>>> host config resetAfterCommit <<<<<<') container.applyUpdate(); }, getChildHostContext: function () { // console.log('>>>>>> host config getChildHostContext <<<<<<') return childHostContext; }, createInstance: function (type, newProps, container) { // console.log('>>>>>> host config createInstance <<<<<<') var node = new VNode({ type: type, props: newProps, container: container }); gStore.setVNode(node.id, node); return node; }, createTextInstance: function (text, container) { // console.log('>>>>>> host config createTextInstance <<<<<<') var node = new VNode({ type: TYPE_TEXT, props: null, container: container }); node.text = text; gStore.setVNode(node.id, node); return node; }, commitTextUpdate: function (node, oldText, newText) { // console.log('>>>>>> host config commitTextUpdate <<<<<<') if (oldText !== newText) { node.text = newText; node.update(); } }, prepareUpdate: function (node, type, lastProps, nextProps) { // console.log('>>>>>> host config prepareUpdate <<<<<<') lastProps = processProps(lastProps, node); nextProps = processProps(nextProps, node); return diffProperties(lastProps, nextProps); }, commitUpdate: function (node, updatePayload, type, oldProps, newProps) { // console.log('>>>>>> host config commitUpdate <<<<<<') node.props = processProps(newProps, node); node.update(updatePayload); }, appendInitialChild: function (parent, child) { // console.log('>>>>>> host config appendInitialChild <<<<<<', parent) parent.appendChild(child); }, appendChild: function (parent, child) { // console.log('>>>>>> host config appendChild <<<<<<') parent.appendChild(child); }, insertBefore: function (parent, child, beforeChild) { // console.log('>>>>>> host config insertBefore <<<<<<') parent.insertBefore(child, beforeChild); }, removeChild: function (parent, child) { // console.log('>>>>>> host config removeChild <<<<<<') parent.removeChild(child); gStore.unsetVNode(child.id); }, finalizeInitialChildren: function () { // console.log('>>>>>> host config finalizeInitialChildren <<<<<<') return false; }, appendChildToContainer: function (container, child) { // console.log('>>>>>> host config appendChildToContainer <<<<<<', container) container.appendChild(child); child.mounted = true; }, insertInContainerBefore: function (container, child, beforeChild) { // console.log('>>>>>> host config insertInContainerBefore <<<<<<') container.insertBefore(child, beforeChild); }, removeChildFromContainer: function (container, child) { // console.log('>>>>>> host config removeChildFromContainer <<<<<<') container.removeChild(child); }, hideInstance: function (instance) { var _a; // console.log('>>>>>> host config hideInstance <<<<<<') var originStyle = (_a = instance.props) === null || _a === void 0 ? void 0 : _a.style; var newStyle = Object.assign({}, originStyle || {}, { display: 'none' }); // 微信和阿里的小程序都不支持在内联样式中加`important!` instance.props = Object.assign({}, instance.props || {}, { style: newStyle }); instance.update(); }, hideTextInstance: function (instance) { // console.log('>>>>>> host config hideTextInstance <<<<<<') instance.text = ''; instance.update(); }, unhideInstance: function (instance, props) { // console.log('>>>>>> host config unhideInstance <<<<<<') instance.props = props; instance.update(); }, unhideTextInstance: function (instance, text) { // console.log('>>>>>> host config unhideTextInstance <<<<<<') instance.text = text; instance.update(); }, commitMount: function () { }, schedulePassiveEffects: scheduleDeferredCallback, cancelPassiveEffects: cancelDeferredCallback, shouldYield: shouldYield, scheduleDeferredCallback: scheduleDeferredCallback, cancelDeferredCallback: cancelDeferredCallback, supportsMutation: true, };