@react-slate/core
Version:
Write interactive CLI apps with React
101 lines • 3.93 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const shallowequal_1 = __importDefault(require("shallowequal"));
const createElement_1 = __importDefault(require("./createElement"));
const Text_1 = __importDefault(require("./nodes/Text"));
const Paragraph_1 = __importDefault(require("./nodes/Paragraph"));
const View_1 = __importDefault(require("./nodes/View"));
const NOOP = () => { };
const RETURN_EMPTY_OBJ = () => ({});
const NO = () => false;
function createReconcilerConfig(containerInstance, onFlush) {
return {
// Create instance of host environment specific node or instance of a component.
createInstance(type, props) {
return createElement_1.default(type, props);
},
createTextInstance(text) {
return createElement_1.default(Text_1.default.TAG, { children: text });
},
// Container handlers
insertInContainerBefore(container, child, childBefore) {
container.prependChild(child, container.findChild(childBefore));
},
appendChildToContainer(container, child) {
container.appendChild(child);
},
removeChildFromContainer(container, child) {
container.removeChild(child);
},
// Default handlers
appendInitialChild(parentInstance, child) {
parentInstance.appendChild(child);
},
appendChild(parentInstance, child) {
parentInstance.appendChild(child);
},
removeChild(parentInstance, child) {
parentInstance.removeChild(child);
},
insertBefore(parentInstance, child, childBefore) {
parentInstance.prependChild(child, parentInstance.findChild(childBefore));
},
// Update handlers
prepareUpdate() {
return true;
},
commitUpdate(instance, _updatePayload, _type, oldProps, newProps) {
if (newProps.onLayout !== instance.onLayoutHook) {
instance.onLayoutHook = newProps.onLayout;
}
instance.eventListener.setOnClickListener(newProps.onClick);
instance.eventListener.setOnWheelListener(newProps.onWheel);
instance.testID = newProps.testID;
if (!shallowequal_1.default(oldProps, newProps)) {
if (instance instanceof View_1.default) {
instance.setLayoutStyle(newProps.layoutStyle);
}
else if (instance instanceof Text_1.default) {
instance.style = newProps.style;
instance.setBody(newProps.children);
}
else if (instance instanceof Paragraph_1.default) {
instance.style = newProps.style;
}
}
},
commitTextUpdate(textInstance, oldText, newText) {
textInstance.setBody(newText);
},
resetAfterCommit() {
onFlush();
},
// Misc
getPublicInstance(inst) {
return inst;
},
shouldSetTextContent: NO,
commitMount: NOOP,
getRootHostContext: RETURN_EMPTY_OBJ,
getChildHostContext: RETURN_EMPTY_OBJ,
prepareForCommit: NOOP,
resetTextContent: NOOP,
finalizeInitialChildren: NO,
supportsMutation: true,
shouldDeprioritizeSubtree: NO,
scheduleDeferredCallback: NOOP,
cancelDeferredCallback: NOOP,
setTimeout,
clearTimeout,
now: () => Date.now(),
noTimeout: undefined,
isPrimaryRenderer: true,
supportsHydration: false,
supportsPersistence: false,
};
}
exports.default = createReconcilerConfig;
//# sourceMappingURL=reconcilerConfig.js.map