Created
December 27, 2017 18:54
-
-
Save ssomnoremac/042c029769a80cfe0e58e1762b76e67e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as AbsintheSocket from "@absinthe/socket"; | |
import {Socket as PhoenixSocket} from "phoenix"; | |
import {createFetcher, createSubscriber} from "@absinthe/socket-relay"; | |
let instance = null | |
const errorFun = error => console.warn(error) | |
export default class RelayEnvironmentService { | |
static init(params) { | |
const absintheSocket = AbsintheSocket.create( | |
new PhoenixSocket("ws://localhost:4000/socket", {params}) | |
); | |
const env = new Environment({ | |
network: Network.create( | |
createFetcher(absintheSocket, errorFun), | |
createSubscriber(absintheSocket, errorFun) | |
), | |
store: new Store(new RecordSource()) | |
}); | |
instance = env | |
return env | |
} | |
static get() { | |
if(instance){ | |
return instance | |
} else { | |
console.log("you must initialize the Relay env service") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment