Skip to content

Instantly share code, notes, and snippets.

@tkdn
tkdn / 2018-3-28.md
Created December 29, 2018 11:53
HOCs と TypeScript における型付けの肝

React HOCs on TypeScript

参考: https://medium.com/@jrwebdev/react-higher-order-component-patterns-in-typescript-42278f7590fb

まだ HOC と TypeScript の良い落としどころが見えてないが、何となく理解しつつある現状。 「TypeScript こわい」から卒業したのと、良記事があったので簡単にまとめておきます。

HOCs と TypeScript の相性

悪い。 => 型を設定することが難しい。 しかしやっていきたいので、any を使わずに整理していこう。

@tkdn
tkdn / pluck.ts
Last active November 9, 2018 02:41
like `array_pluck` on Laravel
const pluck = (
array: Array<{[key: any]: value: any}>,
props: string[],
pickedKey: string,
): {[valuePickedByKey: any]: {[prop:any]: any}} => {
return array.reduce((prevOut, item) => {
const valuePickedByKey = item[pickedKey];
const pickedObj = props.reduce((prevItem, pickProp) => {
return {
...prevItem,
@tkdn
tkdn / pluck.ts
Created November 9, 2018 02:37
like `array_pluck` on Laravel
const pluck = (
array: Array<{[key: any]: value: any}>,
props: string[],
pickedKey: string,
): {[valuePickedByKey: any]: {[prop:any]: any}} => {
return array.reduce((prevOut, item) => {
const valuePickedByKey = item[pickedKey];
const pickedObj = props.reduce((prevItem, pickProp) => {
return {
...prevItem,
@tkdn
tkdn / summary.md
Created August 30, 2018 04:23
GraphQL について知っておきべく事

以下、記事の要約と個人的な疑問点などです。 GraphQL: Everything You Need to Know – Weblab Technology – Medium

また記事中に出てくるサンプルについてはより削ぎ落としたもので、依存がほとんどない。 GraphQL はクライアントからすると、クライアントキャッシングやその他課題はあるものの、クエリ言語である以外何者でもなさそうというがよく分かる。


@tkdn
tkdn / index.test.tsx
Created August 13, 2018 08:34
Next.js' `nextjs-dynamic-routes` unit-test
import { Index } from '@Components/pages'
import * as React from 'react'
import { cleanup, render } from 'react-testing-library'
jest.mock('../../../routes', () => {
const React = require('react')
return {
Link: ({ children }) => {
return <div>{children}</div>
}
@tkdn
tkdn / Brewfile
Last active August 28, 2019 09:49
tap "fujiwara/tap"
tap "getsentry/tools"
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/cask-versions"
tap "homebrew/core"
tap "libero18/mycask"
tap "olleolleolle/adr-tools"
tap "rcmdnk/file"
tap "stns/stns_passwd"
@tkdn
tkdn / Brewfile
Last active April 9, 2021 19:25
ReMac
tap "fujiwara/tap"
tap "getsentry/tools"
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/cask-versions"
tap "homebrew/core"
tap "homebrew/services"
tap "libero18/mycask"
tap "olleolleolle/adr-tools"
tap "rcmdnk/file"
@tkdn
tkdn / foo.jsx
Created June 16, 2017 14:28 — forked from tmeasday/foo.jsx
Redux container
// This is a vastly simplified implementation of what a Redux container would do
class MyComponentContainer extends Component {
mapStateToProps(state) {
// this function is specific to this particular container
return state.foo.bar;
}
render() {
// This is how you get the current state from Redux,
// and would be identical, no mater what mapStateToProps does
export function prevLocation(state = {
refDomNode: null,
method: null
}, action) {
switch (action.type) {
case LOCATION_CHANGE:
const method = action.payload.action
return Object.assign({},state,{
method: method
})
@tkdn
tkdn / file0.js
Last active August 29, 2015 14:16
jQuery その先のUIアニメーション ref: http://qiita.com/tkdn/items/fc8425605bdbcfc3f893
$(function() {
var action = (function(jqObject) {
var content = jqObject.next('.content');
var contentParent = content.parent();
if(contentParent.hasClass('active')){
content.slideUp('250',function(){
contentParent.removeClass('active');
});
} else {
contentParent.addClass('active');