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