hookable 5.1.1 → 5.1.2
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.
- package/README.md +4 -4
- package/dist/index.cjs +11 -1
- package/dist/index.mjs +11 -1
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ hooks.callHook('hello')
|
|
|
44
44
|
```js
|
|
45
45
|
import { Hookable } from 'hookable'
|
|
46
46
|
|
|
47
|
-
export default class
|
|
47
|
+
export default class FooLib extends Hookable {
|
|
48
48
|
constructor() {
|
|
49
49
|
// Call to parent to initialize
|
|
50
50
|
super()
|
|
@@ -62,7 +62,7 @@ export default class Foo extends Hookable {
|
|
|
62
62
|
**Inside plugins, register for any hook:**
|
|
63
63
|
|
|
64
64
|
```js
|
|
65
|
-
const lib =
|
|
65
|
+
const lib = new FooLib()
|
|
66
66
|
|
|
67
67
|
// Register a handler for `hook2`
|
|
68
68
|
lib.hook('hook2', async () => { /* ... */ })
|
|
@@ -77,7 +77,7 @@ lib.addHooks({
|
|
|
77
77
|
**Unregistering hooks:**
|
|
78
78
|
|
|
79
79
|
```js
|
|
80
|
-
const lib =
|
|
80
|
+
const lib = new FooLib()
|
|
81
81
|
|
|
82
82
|
const hook0 = async () => { /* ... */ }
|
|
83
83
|
const hook1 = async () => { /* ... */ }
|
|
@@ -101,7 +101,7 @@ lib.removeHook('hook2', hook2)
|
|
|
101
101
|
**Triggering a hook handler once:**
|
|
102
102
|
|
|
103
103
|
```js
|
|
104
|
-
const lib =
|
|
104
|
+
const lib = new FooLib()
|
|
105
105
|
|
|
106
106
|
const unregister = lib.hook('hook0', async () => {
|
|
107
107
|
// Unregister as soon as the hook is executed
|
package/dist/index.cjs
CHANGED
|
@@ -72,7 +72,9 @@ class Hookable {
|
|
|
72
72
|
}
|
|
73
73
|
if (deprecatedHookObj) {
|
|
74
74
|
if (!deprecatedHookObj.message) {
|
|
75
|
-
console.warn(
|
|
75
|
+
console.warn(
|
|
76
|
+
`${originalName} hook has been deprecated` + (deprecatedHookObj.to ? `, please use ${deprecatedHookObj.to}` : "")
|
|
77
|
+
);
|
|
76
78
|
} else {
|
|
77
79
|
console.warn(deprecatedHookObj.message);
|
|
78
80
|
}
|
|
@@ -110,9 +112,17 @@ class Hookable {
|
|
|
110
112
|
}
|
|
111
113
|
deprecateHook(name, deprecated) {
|
|
112
114
|
this._deprecatedHooks[name] = deprecated;
|
|
115
|
+
const _hooks = this._hooks[name] || [];
|
|
116
|
+
this._hooks[name] = void 0;
|
|
117
|
+
for (const hook of _hooks) {
|
|
118
|
+
this.hook(name, hook);
|
|
119
|
+
}
|
|
113
120
|
}
|
|
114
121
|
deprecateHooks(deprecatedHooks) {
|
|
115
122
|
Object.assign(this._deprecatedHooks, deprecatedHooks);
|
|
123
|
+
for (const name in deprecatedHooks) {
|
|
124
|
+
this.deprecateHook(name, deprecatedHooks[name]);
|
|
125
|
+
}
|
|
116
126
|
}
|
|
117
127
|
addHooks(configHooks) {
|
|
118
128
|
const hooks = flatHooks(configHooks);
|
package/dist/index.mjs
CHANGED
|
@@ -68,7 +68,9 @@ class Hookable {
|
|
|
68
68
|
}
|
|
69
69
|
if (deprecatedHookObj) {
|
|
70
70
|
if (!deprecatedHookObj.message) {
|
|
71
|
-
console.warn(
|
|
71
|
+
console.warn(
|
|
72
|
+
`${originalName} hook has been deprecated` + (deprecatedHookObj.to ? `, please use ${deprecatedHookObj.to}` : "")
|
|
73
|
+
);
|
|
72
74
|
} else {
|
|
73
75
|
console.warn(deprecatedHookObj.message);
|
|
74
76
|
}
|
|
@@ -106,9 +108,17 @@ class Hookable {
|
|
|
106
108
|
}
|
|
107
109
|
deprecateHook(name, deprecated) {
|
|
108
110
|
this._deprecatedHooks[name] = deprecated;
|
|
111
|
+
const _hooks = this._hooks[name] || [];
|
|
112
|
+
this._hooks[name] = void 0;
|
|
113
|
+
for (const hook of _hooks) {
|
|
114
|
+
this.hook(name, hook);
|
|
115
|
+
}
|
|
109
116
|
}
|
|
110
117
|
deprecateHooks(deprecatedHooks) {
|
|
111
118
|
Object.assign(this._deprecatedHooks, deprecatedHooks);
|
|
119
|
+
for (const name in deprecatedHooks) {
|
|
120
|
+
this.deprecateHook(name, deprecatedHooks[name]);
|
|
121
|
+
}
|
|
112
122
|
}
|
|
113
123
|
addHooks(configHooks) {
|
|
114
124
|
const hooks = flatHooks(configHooks);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hookable",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.2",
|
|
4
4
|
"description": "Awaitable hook system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hook",
|
|
@@ -21,24 +21,24 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "unbuild",
|
|
26
|
-
"lint": "eslint --ext .ts src",
|
|
27
|
-
"prepublish": "yarn build",
|
|
28
|
-
"release": "yarn test && yarn build && standard-version && git push --follow-tags && npm publish",
|
|
29
|
-
"test": "yarn lint && yarn jest"
|
|
30
|
-
},
|
|
31
24
|
"devDependencies": {
|
|
32
25
|
"@nuxtjs/eslint-config-typescript": "latest",
|
|
33
|
-
"
|
|
34
|
-
"babel-jest": "latest",
|
|
26
|
+
"c8": "latest",
|
|
35
27
|
"codecov": "latest",
|
|
36
28
|
"eslint": "latest",
|
|
37
|
-
"expect-type": "^0.
|
|
38
|
-
"
|
|
29
|
+
"expect-type": "^0.13.0",
|
|
30
|
+
"vitest": "latest",
|
|
39
31
|
"standard-version": "latest",
|
|
40
|
-
"ts-jest": "latest",
|
|
41
32
|
"typescript": "latest",
|
|
42
33
|
"unbuild": "latest"
|
|
34
|
+
},
|
|
35
|
+
"packageManager": "pnpm@7.9.0",
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "unbuild",
|
|
38
|
+
"lint": "eslint --ext .ts src",
|
|
39
|
+
"prepublish": "pnpm build",
|
|
40
|
+
"release": "pnpm test && pnpm build && standard-version && git push --follow-tags && pnpm publish",
|
|
41
|
+
"test": "pnpm lint && vitest run",
|
|
42
|
+
"test:types": "tsc --noEmit"
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
}
|