UNPKG

@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.12 kB
import _newArrowCheck from"babel-runtime/helpers/newArrowCheck";import{append,remove,replace}from"@jumpn/utils-array";import"phoenix";import _extends from"babel-runtime/helpers/extends";import{errorsToString,getOperationType,requestToCompat}from"@jumpn/utils-graphql";import{hasIn,map}from"@jumpn/utils-composite";var _this$2=void 0,handlePush=function(n,e){return _newArrowCheck(this,_this$2),n.receive("ok",e.onSucceed).receive("error",e.onError).receive("timeout",e.onTimeout)}.bind(void 0),_this$4=void 0,getNotifier=function(n,e){return _newArrowCheck(this,_this$4),function(i){return _newArrowCheck(this,_this$4),i[n]&&i[n](e)}.bind(this)}.bind(void 0),getHandlerName=function(n){return _newArrowCheck(this,_this$4),"on"+String(n)}.bind(void 0),notify=function(n,e,i){return _newArrowCheck(this,_this$4),n.observers.forEach(getNotifier(getHandlerName(e),i))}.bind(void 0),_this$3=void 0,notifyall=function(n,e,i){return _newArrowCheck(this,_this$3),n.forEach(function(n){return _newArrowCheck(this,_this$3),notify(n,e,i)}.bind(this))}.bind(void 0),_this$7=void 0,find=function(n,e,i){return _newArrowCheck(this,_this$7),n.find(hasIn([e],i))}.bind(void 0),_this$6=void 0,createEventHandler=function(n,e){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(n.notifiers,"request",e);s&&i.apply(void 0,[n,s].concat(t))}.bind(this)}.bind(this)}.bind(void 0),createPushHandler=function(n,e,i){return _newArrowCheck(this,_this$6),map(createEventHandler(e,i),n)}.bind(void 0),_this$9=void 0,findIndex=function(n,e,i){return _newArrowCheck(this,_this$9),n.findIndex(hasIn([e],i))}.bind(void 0),_this$8=void 0,remove$1=function(n){return _newArrowCheck(this,_this$8),function(e){return _newArrowCheck(this,_this$8),remove(findIndex(e,"request",n.request),1,e)}.bind(this)}.bind(void 0),_this$10=void 0,refresh=function(n){return _newArrowCheck(this,_this$10),function(e){return _newArrowCheck(this,_this$10),replace(findIndex(e,"request",n.request),[n],e)}.bind(this)}.bind(void 0),_this$11=void 0,updateNotifiers=function(n,e){return _newArrowCheck(this,_this$11),n.notifiers=e(n.notifiers),n}.bind(void 0),_this$5=void 0,notifyStart=function(n){return _newArrowCheck(this,_this$5),notify(n,"Start",n)}.bind(void 0),onSubscriptionSucceed=function(n,e,i){var r=i.subscriptionId;_newArrowCheck(this,_this$5);var t=_extends({},e,{subscriptionId:r});updateNotifiers(n,refresh(t)),notifyStart(t)}.bind(void 0),abortRequest=function(n,e,i){_newArrowCheck(this,_this$5),updateNotifiers(n,remove$1(e)),notify(e,"Abort",i)}.bind(void 0),onError=function(n,e,i){return _newArrowCheck(this,_this$5),abortRequest(n,e,new Error(i))}.bind(void 0),onSubscriptionResponse=function(n,e,i){_newArrowCheck(this,_this$5),i.errors?onError(n,e,errorsToString(i.errors)):onSubscriptionSucceed(n,e,i)}.bind(void 0),onQueryOrMutationResponse=function(n,e,i){_newArrowCheck(this,_this$5),updateNotifiers(n,remove$1(e)),notify(e,"Result",i)}.bind(void 0),onTimeout=function(n,e){return _newArrowCheck(this,_this$5),notify(e,"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(n,e,i){return _newArrowCheck(this,_this$5),handlePush(n.channel.push("doc",requestToCompat(e)),createPushHandler(i,n,e))}.bind(void 0),pushRequest=function(n,e){_newArrowCheck(this,_this$5),"subscription"===e.operationType?send$2(n,e.request,subcriptionHandler):(notifyStart(e),send$2(n,e.request,queryOrMutationHandler))}.bind(void 0),_this$1=void 0,createChannelJoinHandler=function(n){return _newArrowCheck(this,_this$1),{onError:function(e){return _newArrowCheck(this,_this$1),notifyall(n.notifiers,"Error",new Error("channel join: "+String(e)))}.bind(this),onSucceed:function(){return _newArrowCheck(this,_this$1),n.notifiers.forEach(function(e){return _newArrowCheck(this,_this$1),pushRequest(n,e)}.bind(this))}.bind(this),onTimeout:function(){return _newArrowCheck(this,_this$1),notifyall(n.notifiers,"Error",new Error("channel join: timeout"))}.bind(this)}}.bind(void 0),joinChannel=function(n){return _newArrowCheck(this,_this$1),handlePush(n.channel.join(),createChannelJoinHandler(n)),n.channelJoinCreated=!0,n}.bind(void 0),_this$12=void 0,create=function(n){return _newArrowCheck(this,_this$12),{request:n,observers:[],operationType:getOperationType(n.operation),subscriptionId:void 0}}.bind(void 0),_this=void 0,connectOrJoinChannel=function(n){_newArrowCheck(this,_this),n.phoenixSocket.isConnected()?joinChannel(n):n.phoenixSocket.connect()}.bind(void 0),sendNew=function(n,e){_newArrowCheck(this,_this);var i=create(e);return updateNotifiers(n,append([i])),n.channelJoinCreated?pushRequest(n,i):connectOrJoinChannel(n),i}.bind(void 0),send=function(n,e){return _newArrowCheck(this,_this),find(n.notifiers,"request",e)||sendNew(n,e)}.bind(void 0);export default send; //# sourceMappingURL=send.js.map