This file contains 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
upstream websocket { | |
server localhost:3000; | |
} | |
server { | |
listen 80; | |
server_name localhost; | |
access_log /var/log/nginx/websocket.access.log main; |
This file contains 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
function humanize(num){ | |
var ones = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', | |
'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', | |
'seventeen', 'eighteen', 'nineteen']; | |
var tens = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', | |
'ninety']; | |
var numString = num.toString(); | |
if (num < 0) throw new Error('Negative numbers are not supported.'); |
This file contains 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
// 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; |
This file contains 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 { Action } from 'redux'; | |
interface User { | |
name: string; | |
age: number; | |
} | |
export interface LoadingState { | |
users: boolean; | |
} |
This file contains 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 { User, LoadUsersRequest, LoadUsersSuccess, LoadUsersError } from './types'; | |
export const loadUsersRequest = (): LoadUsersRequest => ({ | |
type: 'loadUsersRequest', | |
}); | |
export const loadUsersSuccess = (users: User[]): LoadUsersSuccess => ({ | |
type: 'loadUsersSuccess', | |
users, | |
}); |
This file contains 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 { 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[]> |
This file contains 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 produce from 'immer'; | |
import { ApplicationState, ApplicationAction } from './types'; | |
export const initialState: ApplicationState = { | |
loading: { | |
users: false, | |
}, | |
users: [], | |
} |
This file contains 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
const carsReducer = (state = carState, action) => { | |
switch (action.type) { | |
"loadUsersSuccess": | |
} | |
} |
This file contains 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 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'; |
NewerOlder