-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiny-observables.js
1 lines (1 loc) · 5.48 KB
/
tiny-observables.js
1
var Observe=function(e){function __webpack_require__(t){if(r[t])return r[t].exports;var n=r[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,__webpack_require__),n.l=!0,n.exports}var r={};return __webpack_require__.m=e,__webpack_require__.c=r,__webpack_require__.i=function(e){return e},__webpack_require__.d=function(e,r,t){__webpack_require__.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},__webpack_require__.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return __webpack_require__.d(r,"a",r),r},__webpack_require__.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=0)}([function(e,r,t){"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r}function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)}Object.defineProperty(r,"__esModule",{value:!0}),r.Observe=void 0;var n=function(){function defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(e,r,t){return r&&defineProperties(e.prototype,r),t&&defineProperties(e,t),e}}(),o=t(1),u=t(2);r.Observe=function(e){function Observe(e){_classCallCheck(this,Observe);var r=_possibleConstructorReturn(this,(Observe.__proto__||Object.getPrototypeOf(Observe)).call(this));return r.action=e,r}return _inherits(Observe,e),n(Observe,[{key:"subscribe",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.__noop__,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.__noop__,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.__noop__,n=new o.Observer({next:e,error:r,complete:t});return n.unsub=this.action(n),n.unsubscribe.bind(n)}}]),Observe}(u.Operators)},function(e,r,t){"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(e,r,t){return r&&defineProperties(e.prototype,r),t&&defineProperties(e,t),e}}();r.Observer=function(){function Observer(e){_classCallCheck(this,Observer),this.subscribed=!0,this.subscription=e}return n(Observer,[{key:"next",value:function(e){var r=this;this.subscribed&&this.__try__(function(){return r.subscription.next(e)})}},{key:"error",value:function(e){var r=this;this.subscribed&&this.__try__(function(){r.subscription.error(e),r.unsubscribe()})}},{key:"complete",value:function(){var e=this;this.subscribed&&this.__try__(function(){e.subscription.complete(),e.unsubscribe()})}},{key:"unsubscribe",value:function(){this.subscribed=!1,this.unsub&&this.unsub()}},{key:"__try__",value:function(e){try{e()}catch(e){throw this.unsubscribe(),e}}}]),Observer}()},function(e,r,t){"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0}),r.Operators=void 0;var n=function(){function defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(e,r,t){return r&&defineProperties(e.prototype,r),t&&defineProperties(e,t),e}}(),o=t(0);r.Operators=function(){function Operators(){_classCallCheck(this,Operators)}return n(Operators,[{key:"map",value:function(e){return this.__operator_factory__(function(r){return function(t){return r.next(e(t))}})}},{key:"delay",value:function(e){return this.__operator_factory__(function(r){return function(t){return setTimeout(function(){return r.next(t)},e)}})}},{key:"filter",value:function(e){return this.__operator_factory__(function(r){return function(t){return e(t)?r.next(t):null}})}},{key:"interval",value:function(e){return this.__operator_factory__(function(r){return function(t){return setInterval(r.next(t),e)}})}},{key:"effect",value:function(e){return this.__operator_factory__(function(r){return function(t){e(t),r.next(t)}})}},{key:"throttle",value:function(e){function throttle(e,r){var t=!1;return function(){t||(e.apply(void 0,arguments),t=!0,setTimeout(function(){return t=!1},r))}}return this.__operator_factory__(function(r){return throttle(function(e){return r.next(e)},e)})}},{key:"debounce",value:function(e){function debounce(e,r){var t;return function(){for(var n=arguments.length,o=Array(n),u=0;u<n;u++)o[u]=arguments[u];clearTimeout(t),t=setTimeout(function(){return e.apply(void 0,o)},r)}}return this.__operator_factory__(function(r){return debounce(function(e){return r.next(e)},e)})}},{key:"__operator_factory__",value:function(e,r,t){var n=this;return new o.Observe(function(o){return n.subscribe(e(o),r?r(o):function(e){return o.error(e)},t?t(o):function(){return o.complete()})})}},{key:"__noop__",value:function(){}}]),Operators}()}]);