- 博客(8)
- 收藏
- 关注
原创 asyncPipe
const sum = pipeAsyncFunction( x => x + 1, x => new Promise(resolve => setTimeout(resolve, 1000, x + 2)), x => x + 3, async x => (await x) + 4, x => x, ); transaction(x => { console.log(x, 'anyMethods'); re
2021-07-17 16:16:30 110
原创 memoize
/** * @file 缓存策略 */ interface NewProxyHandler<T extends object> extends ProxyHandler<T> { cache: Map<any, any> } module _ { const memoize = (fn: Function) => new Proxy(fn, { cache: new Map(), apply(target, th
2021-07-17 16:00:54 176
原创 on-emit
type OnEmit = { arr: Function[]; on: (fn: Function) => void; emit: Function }; const event: OnEmit = { arr: [], on(fn: Function) { this.arr.push(fn); }, emit() { this.arr.forEach(fn => fn()); } };
2021-07-17 15:59:59 72
原创 observer
/** * @file 观察者模式 * 有观察者 被观察者 观察者需要放到被观察者中,被观察者的状态发生改变需要通知观察者 */ module callback5_1 { // 我和我媳妇 需要观察小宝宝心理状态的变化 class Subject { // 被观察者 小宝宝 state: string; observers: any[]; constructor(public name: string) { th
2021-07-17 15:58:36 62
原创 async-await
export const fn = async () => { await 1; }; export var __awaiter: ( thisArg: any, _arguments: Iterable<any>, P: PromiseConstructor, generator: Generator ) => Promise<unknown> = (this && (this as any).__awaiter) || functio
2021-07-17 15:57:27 100
原创 co原理实现
function co(it: Generator): Promise<any> { return new Promise((resolve, reject) => { next(); function next(val?: any) { const { value, done } = it.next(val); if (done) return resolve(value);
2021-07-17 15:56:57 77
原创 deepClone
function deepClone(obj: any, hash: any = new WeakMap()) { if (obj == null) return obj; if (obj instanceof Date) return new Date(obj.getTime()); if (obj instanceof RegExp) return new RegExp(obj); if (typeof obj === 'function') return obj;
2021-07-17 15:54:59 107
原创 Promise ts版实现
Promise ts版实现 /** * @file promise * * promise是一个带有then方法的对象或函数 * value是任何合法的JavaScript值(包括undefined、promiseLike或promise)。 * * pending态时: * 可以过渡到完成或拒绝状态。 * fulfilled态时: * 不能过渡到任何其他状态。 * 必须有一个不能改变的值。 * rejected态时: * 不能过渡到任何其他状
2021-07-17 15:52:02 798
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人