Skip to content

Instantly share code, notes, and snippets.

import { Component } from 'preact';
export interface Props {
cond: boolean | ((prevProps: any) => boolean);
[K: string]: any;
}
export default class ShouldChildrenUpdate extends Component<Props, void> {
prevProps: any = this.props;
shouldComponentUpdate(nextProps: Props) {
interface CurriedFunction2<A, B, C> {
(): CurriedFunction2<A, B, C>;
(a: A): (b: B) => C;
(a: A, b: B): C;
}
interface CurriedFunction3<A, B, C, D> {
(): CurriedFunction3<A, B, C, D>;
(a: A): CurriedFunction2<B, C, D>;
(a: A, b: B): (c: C) => D;
export interface Action<T = any, K extends keyof T = any> {
type: K;
payload: T[K];
}
export type MapAction<T = any> = {
[K in keyof T]: Action<T, K>
};
export type MapActionHandler<S, A extends MapAction> = {
import { h, Component, ComponentConstructor, FunctionalComponent } from 'preact';
import { Stream, mergeArray, Subscription } from 'most';
type AnyComponent<P> = ComponentConstructor<P, any> | FunctionalComponent<P>;
export interface Action<T = any, K extends keyof T= any> {
type: K;
payload: T[K];
}
import { MiddlewareAPI, Middleware, Dispatch } from 'redux';
import { async } from 'most-subject';
import { mergeArray, Stream } from 'most';
import Dispatcher from '@cotto/dispatcher';
import { noop } from './utils';
interface RequireCtx {
dispatcher: Dispatcher;
}
import { MiddlewareAPI } from 'redux';
export type EnhancedStore<T, A> = T & {
dispatch: <K extends keyof A>(type: K, payload: A[K]) => {
type: K, payload: A[K]
}
};
export default function makeTypedDispatch<T extends MiddlewareAPI<any>, A>(store: T): EnhancedStore<T, A> {
const origin = store.dispatch;
import { MiddlewareAPI, Middleware, Dispatch } from 'redux';
import { async } from 'most-subject';
import { mergeArray, Stream } from 'most';
import enhance, { EnhancedStore } from './make-typed-dispatch';
export interface Action<T = any, K extends keyof T = any> {
type: K;
payload: T[K];
}
@typoerr
typoerr / ObserverHOC.ts
Created July 22, 2017 13:46
propsをstreamで受け取れるようにするpreact hoc
import { h, Component, ComponentConstructor, FunctionalComponent } from 'preact';
import { Stream, Subscription, mergeArray } from 'most';
import { noop, hasOwn } from '@utils';
export type AnyComponent<P> = ComponentConstructor<P, any> | FunctionalComponent<P>;
export type StreamableProps<P> = {
[K in keyof P]: Stream<P[K]> | P[K]
};
/*
- storeとつながる
- selectorをstreamで書ける
*/
import { h, Component, ComponentConstructor, FunctionalComponent } from 'preact';
import { Stream, Subscription, from, mergeArray } from 'most';
import { async } from 'most-subject';
import { Store } from 'redux';
import { noop } from '@utils';
export interface Action<T = any, K extends keyof T= any> {
type: K;
payload: T[K];
}
///////////////////////////////////////////////////////////
import { Stream, mergeArray } from 'most';
import { Action } from './types';
import { async } from 'most-subject';