Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 2x 2x 3x 3x 3x 3x 1x 3x | // @flow import {set, unset, get} from 'lodash'; export class OnDeployManager { _map: { [string]: { [string]: Function } }; _map = {} execute = ({ key, value }: { key: string, value: any }): any => { const callbacks = this.findCallback(key); return callbacks.reduce((result: any, callback: Function) => callback(result), {data: value}); } findCallback = (key: string): Array<any> => { return Object.values(get(this._map, [key], {})); } registerCallback = (key: string, callback: Function) => { const callbackId = randomStr(); set(this._map, [key, callbackId], callback); return callbackId; } unregisterCallback = (key: string, callbackId: ?string) => { unset(this._map, [key, callbackId]); } } function randomStr() { return Math.random().toString(36).substr(2, 6); } |