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 Subscriber<T> = (val: T) => void | |
type Unsubscriber = () => void | |
export default class Observable<T> { | |
private subscribers: Subscriber<T>[] = [] | |
private unsubscriber: Unsubscriber | |
private _value: T | |
constructor(source?: (cb: Subscriber<T>) => Unsubscriber) { | |
if (source) { |
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
// use shorter name in local | |
const ADD = `ADD_TOAST_MESSAGE` | |
const REMOVE = `REMOVE_TOAST_MESSAGE` | |
// export as longer name with suffix | |
export { | |
ADD as ADD_TOAST_MESSAGE, | |
REMOVE as REMOVE_TOAST_MESSAGE | |
} |
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 { | |
INIT_SOME_DATA, | |
ADD_SOME_DATA, | |
MOVE_SOME_DATA, | |
REMOVE_SOME_DATA, | |
UPDATE_SOME_DATA | |
} from '../mutation_types' | |
import { ISomeData } from '../model/some_data' |
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 traverse<T, U>(obj: Dictionary<T>, f: (t: T) => Array<U>) : Array<Dictionary<U>> { | |
return sequence( | |
mapValues(obj, t => { | |
return f(t) | |
}) | |
) | |
} | |
export function sequence<T>(obj: Dictionary<Array<T>>) : Array<Dictionary<T>> { | |
function loop<T>(acc: Array<Dictionary<T>>, obj: Dictionary<Array<T>>) : Array<Dictionary<T>> { |
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
el.addEventListener('mousemove', event => { | |
const rect = event.currentTarget.getBoundingClientRect() | |
const pos = { | |
left: event.clientX - rect.left, | |
top: event.clientY - rect.top | |
} | |
}) |
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 const ({ shouldRecord, invertAction, isUndo, isRedo }) => { | |
const history = [] | |
return store => next => action => { | |
if (isUndo(action)) { | |
const invert = invertAction(lastUndoable(history)) | |
history.push(invert) | |
next(invert) | |
return | |
} |
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 FnMapperR<T> = { | |
[K in keyof T]: (...args: any[]) => T[K] | |
} | |
type FnMapper2<T, U, R> = { | |
[K in keyof U]: (t: T, u: U[K]) => R | |
} | |
declare function module <S, G, A, M> (module: { | |
namespaced?: boolean, |
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 { inject, create } from '../../../src/interface' | |
import Counter from './counter' | |
const { Getters, Mutations, Actions } = inject('counter', Counter) | |
interface Todo { | |
id: number | |
isCompleted: boolean | |
title: string | |
} |
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 { Store, ActionContext } from 'vuex' | |
type Actions<S, P> = { | |
[K in keyof P]: (ctx: ActionContext<S, any>, payload: P[K]) => void | Promise<any> | |
} | |
type Mutations<S, P> = { | |
[K in keyof P]: (state: S, payload: P[K]) => void | |
} |
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
interface Emit<Payloads> { | |
<Name extends keyof Payloads>(name: Name, payload: Payloads[Name]): void | |
} | |
interface Observe<Payloads> { | |
<Name extends keyof Payloads>( | |
name: Name, | |
cb: (payload: Payloads[Name]) => void | |
): void | |
} |
OlderNewer