@ray-core/runtime
Version:
Ray 是一个全新的基于 React 的小程序开发框架
161 lines (160 loc) • 7 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var scheduler = __importStar(require("scheduler"));
var constants_1 = require("../constants");
var VNode_1 = __importStar(require("../VNode"));
var diffProperties_1 = __importDefault(require("./diffProperties"));
var gStore_1 = require("../gStore");
var scheduleDeferredCallback = scheduler.unstable_scheduleCallback, cancelDeferredCallback = scheduler.unstable_cancelCallback, shouldYield = scheduler.unstable_shouldYield, now = scheduler.unstable_now;
var rootHostContext = {};
var childHostContext = {};
exports.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_1.default({ type: type, props: newProps, container: container });
gStore_1.gStore.setVNode(node.id, node);
return node;
},
createTextInstance: function (text, container) {
// console.log('>>>>>> host config createTextInstance <<<<<<')
var node = new VNode_1.default({ type: constants_1.TYPE_TEXT, props: null, container: container });
node.text = text;
gStore_1.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 = (0, VNode_1.processProps)(lastProps, node);
nextProps = (0, VNode_1.processProps)(nextProps, node);
return (0, diffProperties_1.default)(lastProps, nextProps);
},
commitUpdate: function (node, updatePayload, type, oldProps, newProps) {
// console.log('>>>>>> host config commitUpdate <<<<<<')
node.props = (0, VNode_1.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_1.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,
};