text: 'use strict';Object.defineProperty(exports,"__esModule",{value:!0});function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread2(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(b,!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(b).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}var isCreateSocketValid=function(a){return"undefined"!=typeof a&&null!==a},isHostValid=function(a){return"string"==typeof a&&a&&""!==a},isPortValid=function(a){return"number"==typeof a&&1<=a&&65535>=a},onCommandValid=function(a){return"function"==typeof a},validate=function(a){var b=a.createSocket,c=a.host,d=a.port,e=a.onCommand;if(!isCreateSocketValid(b))throw new Error("invalid createSocket function");if(!isHostValid(c))throw new Error("invalid host");if(!isPortValid(d))throw new Error("invalid port");if(!onCommandValid(e))throw new Error("invalid onCommand handler")},logger=function(){return function(a){return{features:{log:function(){for(var b=arguments.length,c=Array(b),d=0;d<b;d++)c[d]=arguments[d];var e=c&&1===c.length?c[0]:c;a.send("log",{level:"debug",message:e},!1)},logImportant:function(){for(var b=arguments.length,c=Array(b),d=0;d<b;d++)c[d]=arguments[d];var e=c&&1===c.length?c[0]:c;a.send("log",{level:"debug",message:e},!0)},debug:function(b){var c=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return a.send("log",{level:"debug",message:b},!!c)},warn:function(b){return a.send("log",{level:"warn",message:b},!0)},error:function(b,c){return a.send("log",{level:"error",message:b,stack:c},!0)}}}}},image=function(){return function(a){return{features:{image:function(b){var c=b.uri,d=b.preview,e=b.filename,f=b.width,g=b.height,h=b.caption;return a.send("image",{uri:c,preview:d,filename:e,width:f,height:g,caption:h})}}}}},benchmark=function(){return function(a){var b=a.startTimer;return{features:{benchmark:function(c){var d=[],e=b(),f=function(a){var b=0===d.length?0:d[d.length-1].time,c=e();d.push({title:a,time:c,delta:c-b})};d.push({title:c,time:0,delta:0});var g=function(b){f(b),a.send("benchmark.report",{title:c,steps:d})};return{step:f,stop:g,last:g}}}}}},stateResponses=function(){return function(a){return{features:{stateActionComplete:function(b,c){var d=!!(2<arguments.length&&arguments[2]!==void 0)&&arguments[2];return a.send("state.action.complete",{name:b,action:c},!!d)},stateValuesResponse:function(b,c){var d=!(2<arguments.length&&arguments[2]!==void 0)||arguments[2];return a.send("state.values.response",{path:b,value:c,valid:d})},stateKeysResponse:function(b,c){var d=!(2<arguments.length&&arguments[2]!==void 0)||arguments[2];return a.send("state.keys.response",{path:b,keys:c,valid:d})},stateValuesChange:function(b){return a.send("state.values.change",{changes:b})},stateBackupResponse:function(b){return a.send("state.backup.response",{state:b})}}}}},apiResponse=function(){return function(a){return{features:{apiResponse:function(b,c,d){var e=c&&c.status&&"number"==typeof c.status&&200<=c.status&&299>=c.status;a.send("api.response",{request:b,response:c,duration:d},!e)}}}}},clear=function(){return function(a){return{features:{clear:function(){return a.send("clear")}}}}},repl=function(){return function(reactotron){var myRepls={};return{onCommand:function(_ref){var type=_ref.type,payload=_ref.payload;if("repl."===type.substr(0,5))switch(type.substr(5)){case"ls":reactotron.send("repl.ls.response",Object.keys(myRepls));break;case"execute":reactotron.send("repl.execute.response",function(){return eval(payload)}.call(myRepls));}},features:{repl:function(a,b){if(!a)throw new Error("You must provide a name for your REPL");if(myRepls[a])throw new Error("You are already REPLing an item with that name");myRepls[a]=b}}}}},UNDEFINED="~~~ undefined ~~~",NULL="~~~ null ~~~",FALSE="~~~ false ~~~",ZERO="~~~ zero ~~~",EMPTY_STRING="~~~ empty string ~~~",CIRCULAR="~~~ Circular Reference ~~~",ANONYMOUS="~~~ anonymous function ~~~",INFINITY="~~~ Infinity ~~~",NEGATIVE_INFINITY="~~~ -Infinity ~~~";function getFunctionName(a){var b=a.name;return null===b||void 0===b||""===b?ANONYMOUS:"~~~ ".concat(b,"() ~~~")}function serialize(a){var b=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1],c=[];return JSON.stringify(a,function(a){return function(d,e){if(!0===e)return!0;if(e===1/0)return INFINITY;if(e===-Infinity)return NEGATIVE_INFINITY;if(0===e)return ZERO;if(void 0===e)return UNDEFINED;if(null===e)return NULL;if(!1===e)return FALSE;if(-0===e)return ZERO;if(""===e)return EMPTY_STRING;if(b&&"object"===_typeof(e)&&e.nativeEvent)return e.nativeEvent;switch(_typeof(e)){case"string":return e;case"number":return e;case"function":return getFunctionName(e);}if(e[Symbol.iterator]&&!Array.isArray(e))return _toConsumableArray(e);if(0<c.length){var f=c.indexOf(this);~f?c.splice(f+1):c.push(this),~c.indexOf(e)&&(e=CIRCULAR)}else c.push(e);return null==a?e:a.call(this,d,e)}}(null))}var defaultPerformanceNow=function(){return Date.now()},nativePerformance="undefined"!=typeof window&&window&&(window.performance||window.msPerformance||window.webkitPerformance),performanceNow=defaultPerformanceNow,delta=function(a){return performanceNow()-a};global.nativePerformanceNow?performanceNow=global.nativePerformanceNow:nativePerformance&&(performanceNow=function(){return nativePerformance.now&&nativePerformance.now()});var start=function(){var a=performanceNow();return function(){return delta(a)}},corePlugins=[image(),logger(),benchmark(),stateResponses(),apiResponse(),clear(),repl()],DEFAULT_OPTIONS={createSocket:null,host:"localhost",port:9090,name:"reactotron-core-client",secure:!1,plugins:corePlugins,safeRecursion:!0,onCommand:function(){return null},onConnect:function(){return null},onDisconnect:function(){return null}},reservedFeatures=["options","connected","socket","plugins","configure","connect","send","use","startTimer"],isReservedFeature=function(a){return reservedFeatures.some(function(b){return b===a})};function emptyPromise(){return Promise.resolve("")}(function(a){a.String="string"})(exports.ArgType||(exports.ArgType={}));var ReactotronImpl=function(){function a(){var b=this;_classCallCheck(this,a),_defineProperty(this,"options",Object.assign({},DEFAULT_OPTIONS)),_defineProperty(this,"connected",!1),_defineProperty(this,"socket",null),_defineProperty(this,"plugins",[]),_defineProperty(this,"sendQueue",[]),_defineProperty(this,"isReady",!1),_defineProperty(this,"lastMessageDate",new Date),_defineProperty(this,"customCommands",[]),_defineProperty(this,"customCommandLatestId",1),_defineProperty(this,"startTimer",function(){return start()}),_defineProperty(this,"send",function(a){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},d=!!(2<arguments.length&&void 0!==arguments[2])&&arguments[2],e=new Date,f=e.getTime()-b.lastMessageDate.getTime();0>f&&(f=0),b.lastMessageDate=e;var g={type:a,payload:c,important:!!d,date:e.toISOString(),deltaTime:f},h=serialize(g,b.options.proxyHack);if(b.isReady)try{b.socket.send(h)}catch(a){b.isReady=!1,console.log("An error occured communicating with reactotron. Please reload your app")}else b.sendQueue.push(h)})}return _createClass(a,[{key:"configure",value:function(){var a=this,b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},c=Object.assign({},this.options,b);return validate(c),this.options=c,Array.isArray(this.options.plugins)&&this.options.plugins.forEach(function(b){return a.use(b)}),this}},{key:"close",value:function(){this.connected=!1,this.socket&&this.socket.close&&this.socket.close()}},{key:"connect",value:function(){var a=this;this.connected=!0;var b=this.options,c=b.createSocket,d=b.secure,e=b.host,f=b.environment,g=b.port,i=b.name,j=b.client,k=void 0===j?{}:j,l=b.getClientId,m=this.options,n=m.onCommand,o=m.onConnect,p=m.onDisconnect,q=d?"wss":"ws",r=c("".concat(q,"://").concat(e,":").concat(g)),s=function(){o&&o(),a.plugins.forEach(function(a){return a.onConnect&&a.onConnect()});(l||emptyPromise)().then(function(b){for(a.isReady=!0,a.send("client.intro",_objectSpread2({environment:f},k,{name:i,clientId:b,reactotronCoreClientVersion:"2.8.5"}));0<a.sendQueue.length;){var c=a.sendQueue[0];a.sendQueue=a.sendQueue.slice(1),a.socket.send(c)}})},t=function(){a.isReady=!1,p&&p(),a.plugins.forEach(function(a){return a.onDisconnect&&a.onDisconnect()})},u=function(b){var c=JSON.parse(b);n&&n(c),a.plugins.forEach(function(a){return a.onCommand&&a.onCommand(c)}),"custom"===c.type?a.customCommands.filter(function(a){return"string"==typeof c.payload?a.command===c.payload:a.command===c.payload.command}).forEach(function(a){return a.handler("object"===_typeof(c.payload)?c.payload.args:void 0)}):"setClientId"===c.type&&a.options.setClientId&&a.options.setClientId(c.payload)};return r.on?(r.on("open",s),r.on("close",t),r.on("message",u)):(r.onopen=s,r.onclose=t,r.onmessage=function(a){return u(a.data)}),this.socket=r,this}},{key:"display",value:function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},b=a.name,c=a.value,d=a.preview,e=a.image,f=a.important;this.send("display",{name:b,value:c||null,preview:d||null,image:e||null},void 0!==f&&f)}},{key:"reportError",value:function(a){this.error(a)}},{key:"use",value:function(a){var b=this;if("function"!=typeof a)throw new Error("plugins must be a function");var c=a.bind(this)(this);if("object"!==_typeof(c))throw new Error("plugins must return an object");if(c.features){if("object"!==_typeof(c.features))throw new Error("features must be an object");var d=function(a){var d=c.features[a];if("function"!=typeof d)throw new Error("feature ".concat(a," is not a function"));if(isReservedFeature(a))throw new Error("feature ".concat(a," is a reserved name"));b[a]=d};Object.keys(c.features).forEach(function(a){return d(a)})}return this.plugins.push(c),c.onPlugin&&"function"==typeof c.onPlugin&&c.onPlugin.bind(this)(this),this}},{key:"onCustomCommand",value:function(a,b){var c,d,e,f,g,h=this;if("string"==typeof a?(c=a,d=b):(c=a.command,d=a.handler,e=a.title,f=a.description,g=a.args),!c)throw new Error("A command is required");if(!d)throw new Error("A handler is required for command \"".concat(c,"\""));var i=this.customCommands.filter(function(a){return a.command===c});if(0<i.length&&i.forEach(function(a){console.log(a),h.customCommands=h.customCommands.filter(function(b){return b.id!==a.id}),h.send("customCommand.unregister",{id:a.id,command:a.command})}),g){var j=[];g.forEach(function(a){if(!a.name)throw new Error("A arg on the command \"".concat(c,"\" is missing a name"));if(-1<j.indexOf(a.name))throw new Error("A arg with the name \"".concat(a.name,"\" already exists in the command \"").concat(c,"\""));j.push(a.name)})}var k={id:this.customCommandLatestId,command:c,handler:d,title:e,description:f,args:g};return this.customCommandLatestId+=1,this.customCommands.push(k),this.send("customCommand.register",{id:k.id,command:k.command,title:k.title,description:k.description,args:k.args}),function(){h.customCommands=h.customCommands.filter(function(a){return a.id!==k.id}),h.send("customCommand.unregister",{id:k.id,command:k.command})}}}]),a}();function createClient(a){var b=new ReactotronImpl;return b.configure(a),b}exports.ReactotronImpl=ReactotronImpl,exports.corePlugins=corePlugins,exports.createClient=createClient;
  