不要怂,就是干,撸起袖子干!

Commit 0882dc9b by Safonov Nikita

add removing hooks docs

1 parent 00831299
...@@ -47,13 +47,27 @@ Add a hook to the model ...@@ -47,13 +47,27 @@ Add a hook to the model
| Name | Type | Description | | Name | Type | Description |
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| hooktype | String | | | hooktype | String | |
| [name] | String | Provide a name for the hook function. This serves no purpose, other than the ability to be able to order hooks based on some sort of priority system in the future. | | [name] | String | Provide a name for the hook function. It can be used to remove the hook later or to order hooks based on some sort of priority system in the future. |
| fn | Function | The hook function | | fn | Function | The hook function |
__Aliases:__ hook __Aliases:__ hook
*** ***
<a name="removehook"></a>
## `removeHook(hooktype, name)`
[View code](https://github.com/sequelize/sequelize/blob/008312999ffa7e2ee462162573b32e7c60e7f9f7/lib/hooks.js#L171)
Remove a hook from the model
**Params:**
| Name | Type | Description |
| ---- | ---- | ----------- |
| hooktype | String | |
| name | String | Hook's name you want to remove. |
***
<a name="hashook"></a> <a name="hashook"></a>
## `hasHook(hookType)` ## `hasHook(hookType)`
[View code](https://github.com/sequelize/sequelize/blob/cc8687539fe96f7f64887a04ddf5d48f159f5e92/lib/hooks.js#L172) [View code](https://github.com/sequelize/sequelize/blob/cc8687539fe96f7f64887a04ddf5d48f159f5e92/lib/hooks.js#L172)
......
...@@ -95,6 +95,22 @@ User.afterValidate(function(user, options, fn) { ...@@ -95,6 +95,22 @@ User.afterValidate(function(user, options, fn) {
}) })
``` ```
## Removing hooks
Only a hook with name param can be removed.
```js
var Book = sequelize.define('Book', {
title: DataTypes.STRING
})
Book.addHook('afterCreate', 'notifyUsers', function(book, options) {
// ...
})
Book.removeHook('afterCreate', 'notifyUsers')
```
### Instance hooks ### Instance hooks
The following hooks will emit whenever you're editing a single object... The following hooks will emit whenever you're editing a single object...
......
...@@ -144,7 +144,7 @@ var Hooks = { ...@@ -144,7 +144,7 @@ var Hooks = {
* Add a hook to the model * Add a hook to the model
* *
* @param {String} hooktype * @param {String} hooktype
* @param {String} [name] Provide a name for the hook function. This serves no purpose, other than the ability to be able to order hooks based on some sort of priority system in the future. * @param {String} [name] Provide a name for the hook function. It can be used to remove the hook later or to order hooks based on some sort of priority system in the future.
* @param {Function} fn The hook function * @param {Function} fn The hook function
* *
* @alias hook * @alias hook
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!