Skip to content

Instantly share code, notes, and snippets.

@ssomnoremac
Created December 27, 2017 18:54
Show Gist options
  • Save ssomnoremac/042c029769a80cfe0e58e1762b76e67e to your computer and use it in GitHub Desktop.
Save ssomnoremac/042c029769a80cfe0e58e1762b76e67e to your computer and use it in GitHub Desktop.
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