UNPKG

@uifabric/experiments

Version:

Experimental React components for building experiences for Office 365.

54 lines 2.43 kB
import * as tslib_1 from "tslib"; import { BaseComponentMin } from './BaseComponentMin'; var BaseState = /** @class */ (function (_super) { tslib_1.__extends(BaseState, _super); function BaseState(props, options) { if (options === void 0) { options = {}; } var _this = _super.call(this, props) || this; _this._controlledProps = options.controlledProps || []; _this._transformViewProps = options.transformViewProps || (function (newProps) { return newProps; }); return _this; } BaseState.prototype.componentWillReceiveProps = function (newProps) { for (var _i = 0, _a = this._controlledProps; _i < _a.length; _i++) { var propName = _a[_i]; // tslint:disable-next-line:no-any var controlledPropValue = newProps[propName]; if (controlledPropValue !== undefined && controlledPropValue !== this.state[propName]) { // TODO: should we consolidate this into one setState call? this.setState((_b = {}, _b[propName] = controlledPropValue, _b)); } } var _b; }; BaseState.prototype.render = function () { var controlledProps = this._getControlledProps(); var newProps = tslib_1.__assign({}, this.state, controlledProps); // Need to spread controlledProps again to make sure transformViewProps does not overwrite any controlled props. // TODO: better way to do this than two spreads? filtered write? pass "setState" helper to transformViewProps? newProps = tslib_1.__assign({}, this._transformViewProps(newProps), controlledProps); return this.props.renderView(newProps); }; BaseState.prototype._getControlledProps = function () { var result = {}; for (var _i = 0, _a = this._controlledProps; _i < _a.length; _i++) { var propName = _a[_i]; // tslint:disable-next-line:no-any var value = this.props[propName]; if (value !== undefined) { // tslint:disable-next-line:no-any result[propName] = value; } } return result; }; return BaseState; }(BaseComponentMin)); export { BaseState }; //# sourceMappingURL=BaseState.js.map