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">

44 lines (34 loc) 1.06 kB
// @flow import handlePush from "./handlePush"; import notifierNotifyAll from "./notifier/notifyAll"; import pushRequest from "./pushRequest"; import type {AbsintheSocket} from "./types"; // join Push is reused and so the handler // https://github.com/phoenixframework/phoenix/blob/master/assets/js/phoenix.js#L356 const createChannelJoinHandler = absintheSocket => ({ onError: (errorMessage: string) => notifierNotifyAll( absintheSocket.notifiers, "Error", new Error(`channel join: ${errorMessage}`) ), onSucceed: () => absintheSocket.notifiers.forEach(notifier => pushRequest(absintheSocket, notifier) ), onTimeout: () => notifierNotifyAll( absintheSocket.notifiers, "Error", new Error("channel join: timeout") ) }); const joinChannel = (absintheSocket: AbsintheSocket) => { handlePush( absintheSocket.channel.join(), createChannelJoinHandler(absintheSocket) ); absintheSocket.channelJoinCreated = true; return absintheSocket; }; export default joinChannel;