Skip to content

Instantly share code, notes, and snippets.

Toru Kobayashi koba04

Block or report user

Report or block koba04

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View use-case-logger.ts
import { Dispatch } from 'redux'
export type Dispatch = Dispatch
export const createUseCase = <T>(name: string, usecase: () => Promise<any>) => async () => {
if (process.env.NODE_ENV === 'development') {
console.groupCollapsed(`%c[UseCase]%c ${name}`, 'color: #00c4cc', '')
console.time(name)
performance.mark(`start:${name}`)
}
@koba04
koba04 / 2.ts
Last active Feb 17, 2019
Approaches to normalize Redux Store
View 2.ts
interface User {
id: number;
name: string;
todoIds: number[];
}
interface Todo {
id: number;
body: string;
memoIds: number[];
@koba04
koba04 / NavigationTiming.js
Last active Jul 20, 2018
Web Perf snippets
View NavigationTiming.js
timing = performance.timing;
console.log(
`Unload: ${timing.unloadEventEnd - timing.unloadEventStart}\n`,
`Redirect: ${timing.redirectEnd - timing.redirectStart}\n`,
`App Cache: ${timing.domainLookupStart - timing.fetchStart}\n`,
`DNS: ${timing.domainLookupEnd - timing.domainLookupStart}\n`,
`TCP: ${timing.connectEnd - timing.connectStart}\n`,
`Request: ${timing.responseStart - timing.requestStart}\n`,
`Response: ${timing.responseEnd - timing.responseStart}\n`,
`Processing: ${timing.domComplete - timing.domLoading}\n`,
View browser.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
const initialData = JSON.parse(document.getElementById('initial-data').getAttribute('data-json'));
ReactDOM.hydrate(<App {...initialData} />, document.getElementById('app'));
View server.js
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import express from 'express';
import Html from './Html';
import App from './App';
const app = express();
app.use('/static', express.static('public'));
View Html.js
import React from 'react';
const Html = (props) => {
return (
<html>
<head>
<title>App</title>
</head>
<body>
<div id="app">{props.children}</div>
View browser.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
const initialData = JSON.parse(document.getElementById('initial-data').getAttribute('data-json'));
ReactDOM.render(<App {...initialData} />, document.getElementById('app'));
View server.js
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import express from 'express';
import Html from './Html';
import App from './App';
const app = express();
app.use('/static', express.static('public'));
View Html.js
import React from 'react';
const Html = (props) => {
return (
<html>
<head>
<title>App</title>
</head>
<body>
<div id="app" dangerouslySetInnerHTML={ {__html: props.markup} }></div>
View App.js
import React from 'react';
const App = (props) => {
return <div>Hello {props.name}</div>;
};
export default App;
You can’t perform that action at this time.