@shuvi/hook 0.0.1-pre.3 → 0.0.1-pre.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,2 @@
1
- export declare const executeAsyncParallelHook: (tapFns: (((...args: any[]) => void | Promise<void>) & {
2
- hookName?: string | undefined;
3
- })[], ...args: any[]) => Promise<void[]>;
1
+ import { IHookOpts } from './types';
2
+ export declare const executeAsyncParallelHook: (tapFns: IHookOpts['fn'][], ...args: any[]) => Promise<void[]>;
@@ -1,3 +1,2 @@
1
- export declare const executeAsyncSeriesBailHook: (tapFns: (((...args: any[]) => void | Promise<void>) & {
2
- hookName?: string | undefined;
3
- })[], ...args: any[]) => Promise<unknown>;
1
+ import { IHookOpts } from './types';
2
+ export declare const executeAsyncSeriesBailHook: (tapFns: IHookOpts['fn'][], ...args: any[]) => Promise<unknown>;
@@ -1,3 +1,2 @@
1
- export declare const executeAsyncSeriesHook: (tapFns: (((...args: any[]) => void | Promise<void>) & {
2
- hookName?: string | undefined;
3
- })[], ...args: any[]) => Promise<unknown[]>;
1
+ import { IHookOpts } from './types';
2
+ export declare const executeAsyncSeriesHook: (tapFns: IHookOpts['fn'][], ...args: any[]) => Promise<unknown[]>;
@@ -1,3 +1,2 @@
1
- export declare const executeAsyncSeriesWaterfallHook: (tapFns: (((...args: any[]) => void | Promise<void>) & {
2
- hookName?: string | undefined;
3
- })[], ...args: any[]) => Promise<any>;
1
+ import { IHookOpts } from './types';
2
+ export declare const executeAsyncSeriesWaterfallHook: (tapFns: IHookOpts['fn'][], ...args: any[]) => Promise<any>;
package/esm/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  import { Hookable } from './Hookable';
2
2
  export { Hookable };
3
+ export * from './types';
package/esm/types.js CHANGED
@@ -0,0 +1 @@
1
+ export {};
package/esm/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { IHookOpts } from './types';
2
- export declare const getHooksFunctions: (hooks: IHookOpts<"$$no-initial-value", any[]>[]) => (((...args: any[]) => void | Promise<void>) & {
2
+ export declare const getHooksFunctions: (hooks: IHookOpts[]) => (((...args: any[]) => void | Promise<void>) & {
3
3
  hookName?: string | undefined;
4
4
  })[];
5
- export declare const insertHook: (hooks: IHookOpts<"$$no-initial-value", any[]>[], hook: IHookOpts<"$$no-initial-value", any[]>) => IHookOpts<"$$no-initial-value", any[]>[];
6
- export declare const removeHook: (hooks: IHookOpts<"$$no-initial-value", any[]>[], hookToRemove: IHookOpts<"$$no-initial-value", any[]>) => void;
5
+ export declare const insertHook: (hooks: IHookOpts[], hook: IHookOpts) => IHookOpts<"$$no-initial-value", any[]>[];
6
+ export declare const removeHook: (hooks: IHookOpts[], hookToRemove: IHookOpts) => void;
@@ -1,3 +1,2 @@
1
- export declare const executeAsyncParallelHook: (tapFns: (((...args: any[]) => void | Promise<void>) & {
2
- hookName?: string | undefined;
3
- })[], ...args: any[]) => Promise<void[]>;
1
+ import { IHookOpts } from './types';
2
+ export declare const executeAsyncParallelHook: (tapFns: IHookOpts['fn'][], ...args: any[]) => Promise<void[]>;
@@ -9,7 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.executeAsyncParallelHook = (tapFns, ...args) => __awaiter(void 0, void 0, void 0, function* () {
12
+ exports.executeAsyncParallelHook = void 0;
13
+ const executeAsyncParallelHook = (tapFns, ...args) => __awaiter(void 0, void 0, void 0, function* () {
13
14
  const results = yield Promise.all(tapFns.map(fn => fn(...args)));
14
15
  return results;
15
16
  });
17
+ exports.executeAsyncParallelHook = executeAsyncParallelHook;
@@ -1,3 +1,2 @@
1
- export declare const executeAsyncSeriesBailHook: (tapFns: (((...args: any[]) => void | Promise<void>) & {
2
- hookName?: string | undefined;
3
- })[], ...args: any[]) => Promise<unknown>;
1
+ import { IHookOpts } from './types';
2
+ export declare const executeAsyncSeriesBailHook: (tapFns: IHookOpts['fn'][], ...args: any[]) => Promise<unknown>;
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.executeAsyncSeriesBailHook = (tapFns, ...args) => __awaiter(void 0, void 0, void 0, function* () {
12
+ exports.executeAsyncSeriesBailHook = void 0;
13
+ const executeAsyncSeriesBailHook = (tapFns, ...args) => __awaiter(void 0, void 0, void 0, function* () {
13
14
  let result = [];
14
15
  for (let i = 0; i < tapFns.length; i++) {
15
16
  result = tapFns[i](...args);
@@ -22,3 +23,4 @@ exports.executeAsyncSeriesBailHook = (tapFns, ...args) => __awaiter(void 0, void
22
23
  }
23
24
  return result;
24
25
  });
26
+ exports.executeAsyncSeriesBailHook = executeAsyncSeriesBailHook;
@@ -1,3 +1,2 @@
1
- export declare const executeAsyncSeriesHook: (tapFns: (((...args: any[]) => void | Promise<void>) & {
2
- hookName?: string | undefined;
3
- })[], ...args: any[]) => Promise<unknown[]>;
1
+ import { IHookOpts } from './types';
2
+ export declare const executeAsyncSeriesHook: (tapFns: IHookOpts['fn'][], ...args: any[]) => Promise<unknown[]>;
@@ -9,10 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.executeAsyncSeriesHook = (tapFns, ...args) => __awaiter(void 0, void 0, void 0, function* () {
12
+ exports.executeAsyncSeriesHook = void 0;
13
+ const executeAsyncSeriesHook = (tapFns, ...args) => __awaiter(void 0, void 0, void 0, function* () {
13
14
  let results = [];
14
15
  for (let i = 0; i < tapFns.length; i++) {
15
16
  results.push(yield tapFns[i](...args));
16
17
  }
17
18
  return results;
18
19
  });
20
+ exports.executeAsyncSeriesHook = executeAsyncSeriesHook;
@@ -1,3 +1,2 @@
1
- export declare const executeAsyncSeriesWaterfallHook: (tapFns: (((...args: any[]) => void | Promise<void>) & {
2
- hookName?: string | undefined;
3
- })[], ...args: any[]) => Promise<any>;
1
+ import { IHookOpts } from './types';
2
+ export declare const executeAsyncSeriesWaterfallHook: (tapFns: IHookOpts['fn'][], ...args: any[]) => Promise<any>;
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.executeAsyncSeriesWaterfallHook = (tapFns, ...args) => __awaiter(void 0, void 0, void 0, function* () {
12
+ exports.executeAsyncSeriesWaterfallHook = void 0;
13
+ const executeAsyncSeriesWaterfallHook = (tapFns, ...args) => __awaiter(void 0, void 0, void 0, function* () {
13
14
  for (let i = 0; i < tapFns.length; i++) {
14
15
  let fn = tapFns[i];
15
16
  let promiseResult = yield fn(...args);
@@ -24,3 +25,4 @@ exports.executeAsyncSeriesWaterfallHook = (tapFns, ...args) => __awaiter(void 0,
24
25
  }
25
26
  return args[0];
26
27
  });
28
+ exports.executeAsyncSeriesWaterfallHook = executeAsyncSeriesWaterfallHook;
package/lib/Hookable.js CHANGED
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Hookable = void 0;
12
13
  const AsyncParallelHook_1 = require("./AsyncParallelHook");
13
14
  const AsyncSeriesHook_1 = require("./AsyncSeriesHook");
14
15
  const AsyncSeriesBailHook_1 = require("./AsyncSeriesBailHook");
@@ -16,21 +17,21 @@ const AsyncSeriesWaterfallHook_1 = require("./AsyncSeriesWaterfallHook");
16
17
  const utils_1 = require("./utils");
17
18
  function callSerailWithInitialValue(hooks, args, initialValue) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
19
- const fns = utils_1.getHooksFunctions(hooks);
20
- return AsyncSeriesWaterfallHook_1.executeAsyncSeriesWaterfallHook(fns, initialValue, ...args);
20
+ const fns = (0, utils_1.getHooksFunctions)(hooks);
21
+ return (0, AsyncSeriesWaterfallHook_1.executeAsyncSeriesWaterfallHook)(fns, initialValue, ...args);
21
22
  });
22
23
  }
23
24
  function callSerail(hooks, args, bail) {
24
25
  return __awaiter(this, void 0, void 0, function* () {
25
26
  const thookFn = bail ? AsyncSeriesBailHook_1.executeAsyncSeriesBailHook : AsyncSeriesHook_1.executeAsyncSeriesHook;
26
- const fns = utils_1.getHooksFunctions(hooks);
27
+ const fns = (0, utils_1.getHooksFunctions)(hooks);
27
28
  return thookFn(fns, ...args);
28
29
  });
29
30
  }
30
31
  function callParallel(hooks, args) {
31
32
  return __awaiter(this, void 0, void 0, function* () {
32
- const fns = utils_1.getHooksFunctions(hooks);
33
- return (yield AsyncParallelHook_1.executeAsyncParallelHook(fns, ...args));
33
+ const fns = (0, utils_1.getHooksFunctions)(hooks);
34
+ return (yield (0, AsyncParallelHook_1.executeAsyncParallelHook)(fns, ...args));
34
35
  });
35
36
  }
36
37
  class Hookable {
@@ -43,9 +44,9 @@ class Hookable {
43
44
  hooks = [];
44
45
  this._hooks.set(name, hooks);
45
46
  }
46
- utils_1.insertHook(hooks, hook);
47
+ (0, utils_1.insertHook)(hooks, hook);
47
48
  return () => {
48
- utils_1.removeHook(hooks, hook);
49
+ (0, utils_1.removeHook)(hooks, hook);
49
50
  };
50
51
  }
51
52
  // implement
package/lib/index.js CHANGED
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
2
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.Hookable = void 0;
3
14
  const Hookable_1 = require("./Hookable");
4
- exports.Hookable = Hookable_1.Hookable;
15
+ Object.defineProperty(exports, "Hookable", { enumerable: true, get: function () { return Hookable_1.Hookable; } });
16
+ __exportStar(require("./types"), exports);
package/lib/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { IHookOpts } from './types';
2
- export declare const getHooksFunctions: (hooks: IHookOpts<"$$no-initial-value", any[]>[]) => (((...args: any[]) => void | Promise<void>) & {
2
+ export declare const getHooksFunctions: (hooks: IHookOpts[]) => (((...args: any[]) => void | Promise<void>) & {
3
3
  hookName?: string | undefined;
4
4
  })[];
5
- export declare const insertHook: (hooks: IHookOpts<"$$no-initial-value", any[]>[], hook: IHookOpts<"$$no-initial-value", any[]>) => IHookOpts<"$$no-initial-value", any[]>[];
6
- export declare const removeHook: (hooks: IHookOpts<"$$no-initial-value", any[]>[], hookToRemove: IHookOpts<"$$no-initial-value", any[]>) => void;
5
+ export declare const insertHook: (hooks: IHookOpts[], hook: IHookOpts) => IHookOpts<"$$no-initial-value", any[]>[];
6
+ export declare const removeHook: (hooks: IHookOpts[], hookToRemove: IHookOpts) => void;
package/lib/utils.js CHANGED
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getHooksFunctions = (hooks) => {
3
+ exports.removeHook = exports.insertHook = exports.getHooksFunctions = void 0;
4
+ const getHooksFunctions = (hooks) => {
4
5
  return hooks.map(({ fn, name }) => {
5
6
  fn.hookName = name;
6
7
  return fn;
7
8
  });
8
9
  };
10
+ exports.getHooksFunctions = getHooksFunctions;
9
11
  // mutable sort
10
- exports.insertHook = (hooks, hook) => {
12
+ const insertHook = (hooks, hook) => {
11
13
  let before;
12
14
  if (typeof hook.before === 'string') {
13
15
  before = new Set([hook.before]);
@@ -38,10 +40,12 @@ exports.insertHook = (hooks, hook) => {
38
40
  }
39
41
  return hooks;
40
42
  };
43
+ exports.insertHook = insertHook;
41
44
  // mutable way
42
- exports.removeHook = (hooks, hookToRemove) => {
45
+ const removeHook = (hooks, hookToRemove) => {
43
46
  const indexToRemove = hooks.findIndex(hook => hook === hookToRemove);
44
47
  if (indexToRemove >= 0) {
45
48
  hooks.splice(indexToRemove, 1);
46
49
  }
47
50
  };
51
+ exports.removeHook = removeHook;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/hook",
3
- "version": "0.0.1-pre.3",
3
+ "version": "0.0.1-pre.7",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -22,5 +22,5 @@
22
22
  "build:cjs": "tsc -p tsconfig.build.cjs.json"
23
23
  },
24
24
  "author": "Zheng Yu Tay",
25
- "gitHead": "71af6fe3620aab0a9dd900e6527b4f04a31a8757"
25
+ "gitHead": "b88285b47cd53e0cff2ae55649b37cd1ea258f0b"
26
26
  }