- npx create-react-app my-app
- cd my-app
- yarn add redux react-redux redux-thunk redux-logger redux-devtools-extension react-router-dom classnames connected-react-router history
- yarn start
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
| class Consumer<R> { | |
| subscribe<T extends abstract new (...args: any) => any>(event: T, map: (event: InstanceType<T>) => R): Consumer<R> { | |
| return this; | |
| } | |
| connect(): Consumer<R> { | |
| return this; | |
| } | |
| handle(handler: (event: R) => any): Consumer<R> { | |
| //asdasa | |
| return this; |
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
| let index = 0; | |
| let defaultState = []; | |
| const useState = (state) => { | |
| index++; | |
| if (defaultState[index] === undefined) { | |
| defaultState[index] = state; | |
| } | |
| const setState = (newState) => { | |
| defaultState[index] = newState; |
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 { applyMiddleware, createStore } from "redux"; | |
| import { createLogger } from "redux-logger"; | |
| import thunk from "redux-thunk"; | |
| import { composeWithDevTools } from "redux-devtools-extension/developmentOnly"; | |
| import { routerMiddleware } from "connected-react-router"; | |
| import { createBrowserHistory } from "history"; | |
| import { createRootReducer } from "./reducers"; | |
| export const history = createBrowserHistory(); |
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
| package di | |
| import ( | |
| "----/db" | |
| "----/graph" | |
| "----/routes" | |
| "go.uber.org/dig" | |
| "gopkg.in/mgo.v2" | |
| ) |
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
| const onPaste = (e) => { | |
| e.preventDefault(); | |
| let text = e.clipboardData.getData("text/plain"); | |
| document.execCommand("insertText", false, text); | |
| } |
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
| export function timeAgo(time, label = 'ago') { | |
| const between = Date.now() / 1000 - Number(time); | |
| let lb = ' ' + label; | |
| let secPerMinute = 60; | |
| let secPerHour = secPerMinute * 60; | |
| let secPerDay = secPerHour * 24; | |
| let secPerMonth = secPerDay * 30; | |
| let secPerYear = secPerDay * 365; | |
| if (between < secPerHour) { |
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
| export function TimeDifference(current, previous) { | |
| let msPerMinute = 60 * 1000; | |
| let msPerHour = msPerMinute * 60; | |
| let msPerDay = msPerHour * 24; | |
| let msPerMonth = msPerDay * 30; | |
| let msPerYear = msPerDay * 365; | |
| let elapsed = current - previous; |