UNPKG

its-alive

Version:
2 lines 2.64 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("itsAlive",[],e):"object"==typeof exports?exports.itsAlive=e():t.itsAlive=e()}(this,function(){return function(t){function e(n){if(i[n])return i[n].exports;var r=i[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e){"use strict";function i(t){if(Array.isArray(t)){for(var e=0,i=Array(t.length);e<t.length;e++)i[e]=t[e];return i}return Array.from(t)}function n(){return this._value}function r(t){return this._isFrozen?this:"undefined"==typeof t?this:(this._value=t,this._isQuiet||this.notify(),this)}function u(){for(var t=this,e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];var u=void 0,s=void 0,o=void 0;return this._isFrozen?this:(n.length>0?(o=Math.max(this._inputs.length,n.length),s=[].concat(i(Array(o))).map(function(e,i){return"undefined"!=typeof n[i]?n[i]:t._inputs[i]})):s=this._inputs,u=this._reducer.apply(this,i(s.map(function(t){return t.valueOf()}))),"undefined"==typeof u?this:(this._value=u,this._isQuiet||this.notify(),this))}function s(){var t=this;return this._listeners.forEach(function(e){e.trigger._value=t,e.update()}),this}function o(t){if(arguments.length>1)throw new Error("expected single argument");if("function"!=typeof t)throw new TypeError("expected a function");return this._reducer=t,this}function f(){for(var t=arguments.length,e=Array(t),i=0;i<t;i++)e[i]=arguments[i];return this._inputs=e,this}function h(){for(var t=this,e=arguments.length,i=Array(e),n=0;n<e;n++)i[n]=arguments[n];return i.forEach(function(e){if(!e.hasOwnProperty("_listeners")||!Array.isArray(e._listeners))throw new TypeError("Expected a live value");return e._listeners.push(t),e}),this}function a(){return this.input.apply(this,arguments),this.listenTo.apply(this,arguments),this}function l(){return this._isFrozen=!0,this}function c(){return this._isFrozen=!1,this}function p(){return this._isQuiet=!0,this}function d(){return this._isQuiet=!1,this}function _(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return Object.assign(Object.create(v),{_value:t,_reducer:function(t){return t},_inputs:[],_listeners:[],_isFrozen:!1,_isQuiet:!1,trigger:{_value:null,valueOf:function(){return this._value.valueOf()}}})}Object.defineProperty(e,"__esModule",{value:!0});var v={valueOf:n,set:r,update:u,notify:s,reducer:o,input:f,inputs:f,listenTo:h,listenToInput:a,listenToInputs:a,freeze:l,unfreeze:c,quiet:p,unquiet:d};e.default=_}])}); //# sourceMappingURL=itsAlive.min.js.map