Skip to content

Instantly share code, notes, and snippets.

@masahirompp
masahirompp / react-svg-pan-zoom.d.ts
Created February 25, 2017 14:14
react-svg-pan-zoom.d.ts
declare module 'react-svg-pan-zoom' {
import * as React from 'react'
type Tool = 'auto' | 'none' | 'pan' | 'zoom-in' | 'zoom-out'
type ToolBarPosition = 'none' | 'top' | 'right' | 'bottom' | 'left'
export const ReactSVGPanZoom: ReactSVGPanZoom
interface ReactSVGPanZoom extends React.ComponentClass<ReactSVGPanZoomProps> {}
@masahirompp
masahirompp / ImageUtils.ts
Last active October 8, 2017 04:59
image file to DataUri, DataUri(or image src) to ImageData
export function imageFileToDataUri (file: File) {
return new Promise<string>(done => {
const reader = new FileReader()
reader.onloadend = () => done(reader.result)
reader.readAsDataURL(file)
})
}
export function imageSrcToImageData (imageSrc: string) {
return new Promise<ImageData>(resolve => {
@masahirompp
masahirompp / immutability-helper.d.ts
Created July 27, 2017 02:18
[experiment] Type definitions for immutability-helper
declare module "immutability-helper" {
type UpdateSpec<T> = {
[P in keyof T]?: UpdateSpec<T[P]> | UpdateSpecCommand<T[P]>
}
interface UpdateSpecCommand<S> {
$set?: S
// FIX ME. $pushm, $unshift, $spliceはSが配列の場合のみ使用できるようにしたい
$push?: S
@masahirompp
masahirompp / combination.ts
Last active May 6, 2017 09:56
配列のすべての組み合わせについて、関数を実行する。
import flatten from 'lodash-es/flatten'
/**
* 配列のすべての組み合わせについて、関数を実行する。
* @param fun 関数
* @param cols 配列
* @return {Array}
* @example
* combination((x,y)=>x*y, [1,2,3], [4,5,6])
* => [4,5,6,8,10,12,12,15,18]
@masahirompp
masahirompp / stylus compile
Last active March 8, 2017 02:29
stylus compile
stylus --sourcemap --use ./node_modules/axis --out build app/index.styl
export function preventDefault (func, ...args) {
return e => {
e.preventDefault()
func(...args)
}
}
export function targetValue (func, ...args) {
return e => {
func(e.target.value, ...args)
@masahirompp
masahirompp / react-dnd-touch-backend.d.ts
Created February 25, 2017 14:13
react-dnd-touch-backend.d.ts
declare module 'react-dnd-touch-backend' {
import { Backend } from 'react-dnd'
declare const Backend: Backend
export default Backend
}
@masahirompp
masahirompp / react-dimensions.d.ts
Created February 25, 2017 14:13
react-dimensions.d.ts
declare module 'react-dimensions' {
import * as React from 'react'
interface Dimensions {
<P extends React.Props<any>>(options?: Options): (component: React.ComponentClass<P>) => React.ComponentClass<P>
}
declare const Dimensions: Dimensions
export default Dimensions
<div class="select">
<select>
<option value="a">AAA</option>
<option value="b">BBB</option>
<option value="c">CCC</option>
</select>
</div>
@masahirompp
masahirompp / controller.js
Created February 21, 2015 12:09
javascript mvc (no framework) http://jsfiddle.net/54sjqL6z/
(function(todo) {
'use strict';
// viewの追加イベントを監視。TodoListに新規Todoを追加する。
todo.View.on('add', function(description) {
todo.TodoList.add(new todo.Todo(todo.TodoList.length, description));
todo.View.clearInput();
});
// viewの変更イベントを監視。モデルの状態を更新を命令。