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