Skip to content

Instantly share code, notes, and snippets.

View jakejrichards's full-sized avatar

Jake Richards jakejrichards

  • Palantir
View GitHub Profile
import { ApiGatewayManagementApi } from 'aws-sdk';
// Setup api client to communicate with websocket clients
const apiClient = new ApiGatewayManagementApi({
apiVersion: '2018-11-29',
endpoint: "YOUR_WEBSOCKET_API_ENDPOINT",
});
// Send websocket message to given connectionId
function sendMessage(connectionId: string, data: object) {
// This is a sample of what the event object that gets
// passed to your connect route could look like.
// I've chosen to use an authorizer that will pass
// the userId so that I can store the connectionId with the userId
// in my database
interface APIGatewayWebsocketEvent {
methodArn: string;
queryStringParameters: {
token: string;
import * as _ from 'lodash';
import * as jwt from 'jsonwebtoken';
import * as jwkToPem from 'jwk-to-pem';
import * as moment from 'moment';
import * as request from 'request';
interface DecodedJWT {
aud: string;
iss: string;
exp: number;
import { Action } from 'redux';
interface User {
name: string;
age: number;
}
export interface LoadingState {
users: boolean;
}
import { User, LoadUsersRequest, LoadUsersSuccess, LoadUsersError } from './types';
export const loadUsersRequest = (): LoadUsersRequest => ({
type: 'loadUsersRequest',
});
export const loadUsersSuccess = (users: User[]): LoadUsersSuccess => ({
type: 'loadUsersSuccess',
users,
});
import { ThunkAction } from 'redux-thunk';
import { ApplicationState, ApplicationAction } from './types';
import { loadUsersRequest, loadUsersSuccess, loadUsersError } from './actions';
import * as userService from '../services/userService';
type Effect = ThunkAction<any, ApplicationState, any, ApplicationAction>;
export const loadUsers = (): Effect => (dispatch, getState) => {
dispatch(loadUsersRequest());
// assume userService.loadUsers returns a Promise<User[]>
import produce from 'immer';
import { ApplicationState, ApplicationAction } from './types';
export const initialState: ApplicationState = {
loading: {
users: false,
},
users: [],
}
const carsReducer = (state = carState, action) => {
switch (action.type) {
"loadUsersSuccess":
}
}
import React from 'react';
import ReactDOM from 'react-dom';
import { applyMiddleware, createStore } from 'redux';
import thunk from 'redux-thunk';
import { Provider } from 'react-redux';
import reducer, { initialState } from './store/reducer';
import App from './components/App';
// If you are interested in using the redux devtools
import { composeWithDevTools } from 'redux-devtools-extension';
import ReactGA from 'react-ga';
import auth from './auth.ts'; // Sample authentication provider
const trackingId = "UA-1234567890-1"; // Replace with your Google Analytics tracking ID
ReactGA.initialize(trackingId);
ReactGA.set({
userId: auth.currentUserId(),
// any data that is relevant to the user session
// that you would like to track with google analytics
})