UNPKG

azure-devops-ui

Version:

React components for building web UI in Azure DevOps

1 lines 3 kB
import{__assign,__extends}from"tslib";import"../../CommonImports";import"../../Core/core.css";import*as React from"react";import{ObservableLike}from"../../Core/Observable";var ObserverBase=function(i){function e(e){var t,s=i.call(this,e)||this,r=(s.subscriptions={},{values:{},oldProps:{}});for(t in e)r.values[t]=getPropValue(e[t]);return s.state=r,s}return __extends(e,i),e.getDerivedStateFromProps=function(e,t){t=updateSubscriptionsAndState(t.oldProps,e,t);return null!=t?__assign(__assign({},t),{oldProps:e}):{oldProps:e}},e.prototype.render=function(){var e,t,s={};for(e in this.state.values)"children"!==e&&(s[e]=this.state.values[e]);return"function"==typeof this.props.children?(t=this.props.children)(s):(t=React.Children.only(this.props.children),React.cloneElement(t,__assign(__assign({},t.props),s),t.props.children))},e.prototype.componentDidMount=function(){this.updateSubscriptionsAndStateAfterRender()},e.prototype.componentDidUpdate=function(){this.updateSubscriptionsAndStateAfterRender(),this.props.onUpdate&&this.props.onUpdate()},e.prototype.componentWillUnmount=function(){for(var e in this.subscribedProps)this.unsubscribe(e,this.subscribedProps)},e.prototype.subscribe=function(e,t){var s,r;"children"!==e&&(s=r=void 0,(t=t[e])&&void 0!==t.observableValue&&(t=(r=t).observableValue,s=r.action),ObservableLike.isObservable(t))&&(r=this.onValueChanged.bind(this,e,t,r),ObservableLike.subscribe(t,r,s),this.subscriptions[e]={delegate:r,action:s})},e.prototype.unsubscribe=function(e,t){var s;"children"!==e&&(t=getObservableValue(t[e]),ObservableLike.isObservable(t))&&(s=this.subscriptions[e],ObservableLike.unsubscribe(t,s.delegate,s.action),delete this.subscriptions[e])},e.prototype.updateSubscriptionsAndStateAfterRender=function(){var e=updateSubscriptionsAndState(this.subscribedProps,this.props,this.state,this);null!=e&&this.setState(e),this.subscribedProps=__assign({},this.props)},e.prototype.onValueChanged=function(s,r,e,i,t){var n=!0;s in this.subscriptions&&(n=e&&e.filter?e.filter(i,t):n)&&this.setState(function(e,t){return{values:__assign(__assign({},e.values),((e={})[s]=r.value||i,e))}})},e}(React.Component);function getObservableValue(e){return e&&void 0!==e.observableValue?e.observableValue:e}function getPropValue(e){return ObservableLike.getValue(getObservableValue(e))}function updateSubscriptionsAndState(e,t,s,r){var i,n=__assign({},s),o=!1;if(e)for(var a in e)getObservableValue(e[a])!==(i=getObservableValue(t[a]))&&(r&&r.unsubscribe(a,e),void 0===i)&&(delete n.values[a],o=!0);for(a in t)(e&&getObservableValue(e[a]))!==(i=getObservableValue(t[a]))&&(r&&r.subscribe(a,t),s.values[a]!==getPropValue(i))&&(n.values[a]=getPropValue(i),o=!0);return o?n:null}var Observer=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t}(ObserverBase),UncheckedObserver=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t}(ObserverBase);export{Observer,UncheckedObserver};