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