@dillonkearns/elm-graphql
Version:
<img src="https://cdn.jsdelivr.net/gh/martimatix/logo-graphqelm/logo.svg" alt="dillonearns/elm-graphql logo" width="40%" align="right">
3 lines (2 loc) • 5.32 kB
JavaScript
;function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var _newArrowCheck=_interopDefault(require("babel-runtime/helpers/newArrowCheck")),utilsArray=require("@jumpn/utils-array");require("phoenix");var _extends=_interopDefault(require("babel-runtime/helpers/extends")),utilsGraphql=require("@jumpn/utils-graphql"),utilsComposite=require("@jumpn/utils-composite"),_this$2=void 0,handlePush=function(e,n){return _newArrowCheck(this,_this$2),e.receive("ok",n.onSucceed).receive("error",n.onError).receive("timeout",n.onTimeout)}.bind(void 0),_this$4=void 0,getNotifier=function(e,n){return _newArrowCheck(this,_this$4),function(i){return _newArrowCheck(this,_this$4),i[e]&&i[e](n)}.bind(this)}.bind(void 0),getHandlerName=function(e){return _newArrowCheck(this,_this$4),"on"+String(e)}.bind(void 0),notify=function(e,n,i){return _newArrowCheck(this,_this$4),e.observers.forEach(getNotifier(getHandlerName(n),i))}.bind(void 0),_this$3=void 0,notifyall=function(e,n,i){return _newArrowCheck(this,_this$3),e.forEach(function(e){return _newArrowCheck(this,_this$3),notify(e,n,i)}.bind(this))}.bind(void 0),_this$7=void 0,find=function(e,n,i){return _newArrowCheck(this,_this$7),e.find(utilsComposite.hasIn([n],i))}.bind(void 0),_this$6=void 0,createEventHandler=function(e,n){return _newArrowCheck(this,_this$6),function(i){return _newArrowCheck(this,_this$6),function(){for(var r=arguments.length,t=Array(r),o=0;o<r;o++)t[o]=arguments[o];_newArrowCheck(this,_this$6);var s=find(e.notifiers,"request",n);s&&i.apply(void 0,[e,s].concat(t))}.bind(this)}.bind(this)}.bind(void 0),createPushHandler=function(e,n,i){return _newArrowCheck(this,_this$6),utilsComposite.map(createEventHandler(n,i),e)}.bind(void 0),_this$9=void 0,findIndex=function(e,n,i){return _newArrowCheck(this,_this$9),e.findIndex(utilsComposite.hasIn([n],i))}.bind(void 0),_this$8=void 0,remove$1=function(e){return _newArrowCheck(this,_this$8),function(n){return _newArrowCheck(this,_this$8),utilsArray.remove(findIndex(n,"request",e.request),1,n)}.bind(this)}.bind(void 0),_this$10=void 0,refresh=function(e){return _newArrowCheck(this,_this$10),function(n){return _newArrowCheck(this,_this$10),utilsArray.replace(findIndex(n,"request",e.request),[e],n)}.bind(this)}.bind(void 0),_this$11=void 0,updateNotifiers=function(e,n){return _newArrowCheck(this,_this$11),e.notifiers=n(e.notifiers),e}.bind(void 0),_this$5=void 0,notifyStart=function(e){return _newArrowCheck(this,_this$5),notify(e,"Start",e)}.bind(void 0),onSubscriptionSucceed=function(e,n,i){var r=i.subscriptionId;_newArrowCheck(this,_this$5);var t=_extends({},n,{subscriptionId:r});updateNotifiers(e,refresh(t)),notifyStart(t)}.bind(void 0),abortRequest=function(e,n,i){_newArrowCheck(this,_this$5),updateNotifiers(e,remove$1(n)),notify(n,"Abort",i)}.bind(void 0),onError=function(e,n,i){return _newArrowCheck(this,_this$5),abortRequest(e,n,new Error(i))}.bind(void 0),onSubscriptionResponse=function(e,n,i){_newArrowCheck(this,_this$5),i.errors?onError(e,n,utilsGraphql.errorsToString(i.errors)):onSubscriptionSucceed(e,n,i)}.bind(void 0),onQueryOrMutationResponse=function(e,n,i){_newArrowCheck(this,_this$5),updateNotifiers(e,remove$1(n)),notify(n,"Result",i)}.bind(void 0),onTimeout=function(e,n){return _newArrowCheck(this,_this$5),notify(n,"Error",new Error("request: timeout"))}.bind(void 0),queryOrMutationHandler={onError:onError,onTimeout:onTimeout,onSucceed:onQueryOrMutationResponse},subcriptionHandler={onError:onError,onTimeout:onTimeout,onSucceed:onSubscriptionResponse},send$2=function(e,n,i){return _newArrowCheck(this,_this$5),handlePush(e.channel.push("doc",utilsGraphql.requestToCompat(n)),createPushHandler(i,e,n))}.bind(void 0),pushRequest=function(e,n){_newArrowCheck(this,_this$5),"subscription"===n.operationType?send$2(e,n.request,subcriptionHandler):(notifyStart(n),send$2(e,n.request,queryOrMutationHandler))}.bind(void 0),_this$1=void 0,createChannelJoinHandler=function(e){return _newArrowCheck(this,_this$1),{onError:function(n){return _newArrowCheck(this,_this$1),notifyall(e.notifiers,"Error",new Error("channel join: "+String(n)))}.bind(this),onSucceed:function(){return _newArrowCheck(this,_this$1),e.notifiers.forEach(function(n){return _newArrowCheck(this,_this$1),pushRequest(e,n)}.bind(this))}.bind(this),onTimeout:function(){return _newArrowCheck(this,_this$1),notifyall(e.notifiers,"Error",new Error("channel join: timeout"))}.bind(this)}}.bind(void 0),joinChannel=function(e){return _newArrowCheck(this,_this$1),handlePush(e.channel.join(),createChannelJoinHandler(e)),e.channelJoinCreated=!0,e}.bind(void 0),_this$12=void 0,create=function(e){return _newArrowCheck(this,_this$12),{request:e,observers:[],operationType:utilsGraphql.getOperationType(e.operation),subscriptionId:void 0}}.bind(void 0),_this=void 0,connectOrJoinChannel=function(e){_newArrowCheck(this,_this),e.phoenixSocket.isConnected()?joinChannel(e):e.phoenixSocket.connect()}.bind(void 0),sendNew=function(e,n){_newArrowCheck(this,_this);var i=create(n);return updateNotifiers(e,utilsArray.append([i])),e.channelJoinCreated?pushRequest(e,i):connectOrJoinChannel(e),i}.bind(void 0),send=function(e,n){return _newArrowCheck(this,_this),find(e.notifiers,"request",n)||sendNew(e,n)}.bind(void 0);module.exports=send;
//# sourceMappingURL=send.js.map