UNPKG

react-rebind

Version:

Declarative data binding to React components

139 lines (119 loc) 4.85 kB
(function (global, factory) { if (typeof define === "function" && define.amd) { define(['module', 'exports', 'react', '../utils/ScopedComponent', 'prop-types'], factory); } else if (typeof exports !== "undefined") { factory(module, exports, require('react'), require('../utils/ScopedComponent'), require('prop-types')); } else { var mod = { exports: {} }; factory(mod, mod.exports, global.react, global.ScopedComponent, global.propTypes); global.Scope = mod.exports; } })(this, function (module, exports, _react, _ScopedComponent2, _propTypes) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _react2 = _interopRequireDefault(_react); var _ScopedComponent3 = _interopRequireDefault(_ScopedComponent2); var _propTypes2 = _interopRequireDefault(_propTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Scope = function (_ScopedComponent) { _inherits(Scope, _ScopedComponent); function Scope() { _classCallCheck(this, Scope); return _possibleConstructorReturn(this, (Scope.__proto__ || Object.getPrototypeOf(Scope)).apply(this, arguments)); } _createClass(Scope, [{ key: 'getChildContext', value: function getChildContext() { return { rebindContext: this.getChildRebindContext() }; } }, { key: 'getChildRebindContext', value: function getChildRebindContext() { var rebindContext = Object.assign({}, this.context.rebindContext, { scope: this.scope }); if (this.props.mark !== undefined && this.props.mark !== null) { rebindContext.marks = Object.assign({}, rebindContext.marks, _defineProperty({}, this.props.mark, { scope: this.scope, marks: this.context.rebindContext })); } return rebindContext; } }, { key: 'render', value: function render() { return _react2.default.createElement( _react2.default.Fragment, null, this.props.children ); } }]); return Scope; }(_ScopedComponent3.default); Scope.childContextTypes = { rebindContext: _propTypes2.default.any }; exports.default = Scope; module.exports = exports['default']; });