UNPKG

react-blessed

Version:
83 lines (60 loc) 2.14 kB
/** * React Blessed Update Schemes * ============================= * * Applying updates to blessed nodes correctly. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports['default'] = update; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _lodash = require('lodash'); var _lodash2 = _interopRequireDefault(_lodash); var RAW_ATTRIBUTES = [ // Alignment, Orientation & Presentation 'align', 'valign', 'orientation', 'shrink', 'padding', 'tags', 'shadow', // Font-related 'font', 'fontBold', 'fch', 'ch', 'bold', 'underline', // Flags 'clickable', 'input', 'keyable', 'focused', 'hidden', 'visible', 'scrollable', 'draggable', 'interactive', // Position 'left', 'right', 'top', 'bottom', 'aleft', 'aright', 'atop', 'abottom', // Size 'width', 'height', // Misc 'name', 'hoverText']; /** * Updates the given blessed node. * * @param {BlessedNode} node - Node to update. * @param {object} options - Props of the component without children. */ function update(node, options) { // TODO: enforce some kind of shallow equality? // TODO: handle position for (var key in options) { var value = options[key]; // Setting label if (key === 'label') node.setLabel(value); // Setting content else if (key === 'content') node.setContent(value); // Updating style else if (key === 'style') node.style = _lodash2['default'].merge({}, node.style, value); // Updating items else if (key === 'items') node.setItems(value); // Border edge case else if (key === 'border') node.border = _lodash2['default'].merge({}, node.border, value); // Progress bar else if (key === 'filled' && node.filled !== value) node.setProgress(value); // Raw attributes else for (var i = 0, l = RAW_ATTRIBUTES.length; i < l; i++) { if (key === RAW_ATTRIBUTES[i]) { node[key] = value; break; } } } } module.exports = exports['default'];