Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit e41a2a67
authored
Apr 19, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(promises): have hooks.runHooks() return a promise
1 parent
6e754979
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
4 deletions
lib/dao-factory.js
lib/hooks.js
lib/promise.js
test/hooks.test.js
lib/dao-factory.js
View file @
e41a2a6
...
...
@@ -1224,7 +1224,6 @@ module.exports = (function() {
if
(
!!
err
)
{
return
emitter
.
emit
(
'error'
,
err
)
}
daos
=
newRecords
||
daos
options
.
fields
=
newFields
||
options
.
fields
...
...
lib/hooks.js
View file @
e41a2a6
var
Utils
=
require
(
"./utils"
)
,
Promise
=
require
(
"./promise"
)
/**
* Hooks are function that are called before and after (bulk-) creation/updating/deletion and validation. Hooks can be added to you models in three ways:
...
...
@@ -69,13 +70,14 @@ Hooks.runHooks = function() {
hooks
=
hooks
===
undefined
?
[]
:
[
hooks
]
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
if
(
hooks
.
length
<
1
)
{
return
fn
.
apply
(
this
,
[
null
].
concat
(
args
)
)
return
resolve
(
args
)
}
var
run
=
function
(
hook
)
{
if
(
!
hook
)
{
return
fn
.
apply
(
this
,
[
null
].
concat
(
args
)
)
return
resolve
(
args
)
}
if
(
typeof
hook
===
"object"
)
{
...
...
@@ -86,7 +88,7 @@ Hooks.runHooks = function() {
tick
++
if
(
!!
arguments
[
0
])
{
return
fn
(
arguments
[
0
])
return
reject
(
arguments
[
0
])
}
// daoValues = newValues
...
...
@@ -95,6 +97,9 @@ Hooks.runHooks = function() {
}
run
(
hooks
[
tick
])
}).
spread
(
function
()
{
fn
.
apply
(
self
,
[
null
].
concat
(
Array
.
prototype
.
slice
.
apply
(
arguments
)));
},
fn
);
}
Hooks
.
hook
=
function
()
{
...
...
lib/promise.js
View file @
e41a2a6
...
...
@@ -173,4 +173,10 @@ SequelizePromise.prototype.proxy = function(promise, options) {
return
this
}
SequelizePromise
.
prototype
.
proxySql
=
function
(
promise
)
{
return
this
.
proxy
(
promise
,
{
events
:
[
'sql'
]
});
};
module
.
exports
=
SequelizePromise
;
\ No newline at end of file
test/hooks.test.js
View file @
e41a2a6
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment