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 paths = [ | |
'/settings/:id/:tab', | |
'/profile/:tab(foo)', | |
'/profile/', | |
'/users/:userId', | |
'/', | |
] as const; | |
/** | |
* SPA 内遷移のパス一覧 |
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
// 型に別名を付けても | |
type LooseID = string | |
// 元の型のまま代入できてしまう | |
const id1: LooseID = 'wrong value' | |
// こうすると | |
type StrictID = string & { readonly brand: unique symbol } | |
// 防げる |
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
{ | |
"endOfLine": "lf", | |
"semi": false, | |
"singleQuote": true, | |
"trailingComma": "all" | |
} |
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, { useEffect } from 'react' | |
import { Section, Title, Loading, Todo } from './components' | |
import useTodosStore from './useTodosStore' | |
export default function App() { | |
// このファイルにべた書きされた store インスタンスではなく、コンテキスト経由の store を使うことで、 | |
// テスト時や Storybook を使うときにモックしやすくなる。 | |
const [todos, loading, toggle, fetchTodos] = useTodosStore(store => [ | |
store.todos, | |
store.loading, |
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
/** | |
* 値が null または undefined のときは false, それ以外の値のときは true を返す。 | |
* Array.prototype.filter と組み合わせて null を除去するのに使える。 | |
* | |
* @param value null チェックしたい値 | |
* @example | |
* [0, null, {}].filter(nonNull) // [0, {}] | |
*/ | |
export function nonNull<T>(value: T | null | undefined): value is T { | |
return value !== null && value !== undefined |
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
export function throttle<A extends unknown[]>( | |
func: (...args: A) => unknown, | |
wait = 0, | |
): (...args: A) => void { | |
// Fire the first call immediately | |
let prevTime = Date.now() - wait | |
// Fire trailing calls after wait | |
let trailingCall: ReturnType<typeof setTimeout> | |
return function throttled(...args: A) { |
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
#!/usr/bin/env node | |
const tar = require("tar"); | |
async function scaffold(file) { | |
await tar.extract({ | |
strip: 1, | |
file | |
}); |
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
#!/usr/bin/env node | |
console.log("Hello from Gist!"); |
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
# Node.js Sample for AWS Cloud9 - AWS Cloud9 | |
# https://docs.aws.amazon.com/cloud9/latest/user-guide/sample-nodejs.html#sample-nodejs-install | |
nvm install node | |
nvm alias default v9.5.0 | |
# Installation | Yarn | |
# https://yarnpkg.com/en/docs/install#linux-tab | |
# CentOS / Fedora / RHEL | |
sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo | |
sudo yum install -y yarn |
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
{ | |
"name": "raw-hbs", | |
"version": "1.0.0", | |
"main": "index.js", | |
"author": "kazuma1989 <funifuni.1204@gmail.com>", | |
"license": "MIT", | |
"scripts": { | |
"start": "webpack-dev-server", | |
"build": "cross-env NODE_ENV=production webpack" | |
}, |
NewerOlder