Skip to content

Instantly share code, notes, and snippets.

View arausly's full-sized avatar
🏠
Working from home

arausly

🏠
Working from home
View GitHub Profile
export const connectWebSocket = <T>(
webSocketUrl: string,
pollingUrl: string = "",
updateFunc: (updateItem: T) => any,
registerError?: (errorId: string, err: any, cause?:any) => void,
__isReconnecting__: boolean = false,
__hasPrevConnection: boolean = false
): CleanUpFunction => {
const cleanUpFunctions: CleanUpFunction[] = [];
const fixedWebSocketUrl = convertToWebsocketUrl(webSocketUrl);
@arausly
arausly / index.jsx
Created October 6, 2021 12:54
Correct Suspense Implementation
/***
* Problems with previous solution
*
* 1. No fallback UI was provided
2. You don't need to wrap all individual component in a separate suspense.
3. The component to be suspended must throw a promise if requisite data is not available
*/
import * as React from "react";
@arausly
arausly / QL-Client
Last active October 8, 2022 00:37
GraphQL chat app
import { InMemoryCache } from "apollo-cache-inmemory";
import { createHttpLink } from "apollo-link-http";
import { WebSocketLink } from "apollo-link-ws";
import { ApolloClient } from "apollo-client";
import { split } from "apollo-link";
import { getMainDefinition } from "apollo-utilities";
const httpLink = createHttpLink({ uri: "http://localhost:8080/" });
const wsLink = new WebSocketLink({
uri: `ws://localhost:8080/graphql`,