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 6e754979
authored
Apr 19, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(promises): make sure chaining works
1 parent
af7d2d7e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
8 deletions
lib/promise.js
test/promise.test.js
lib/promise.js
View file @
6e75497
...
@@ -3,6 +3,7 @@ var util = require("util")
...
@@ -3,6 +3,7 @@ var util = require("util")
,
EventEmitter
=
require
(
"events"
).
EventEmitter
,
EventEmitter
=
require
(
"events"
).
EventEmitter
,
proxyEventKeys
=
[
'success'
,
'error'
,
'sql'
]
,
proxyEventKeys
=
[
'success'
,
'error'
,
'sql'
]
,
Utils
=
require
(
'./utils'
)
,
Utils
=
require
(
'./utils'
)
,
INTERNAL
=
function
()
{}
var
SequelizePromise
=
function
(
resolver
)
{
var
SequelizePromise
=
function
(
resolver
)
{
var
self
=
this
;
var
self
=
this
;
...
@@ -28,7 +29,12 @@ var SequelizePromise = function(resolver) {
...
@@ -28,7 +29,12 @@ var SequelizePromise = function(resolver) {
}.
bind
(
this
));
}.
bind
(
this
));
};
};
util
.
inherits
(
SequelizePromise
,
Promise
);
util
.
inherits
(
SequelizePromise
,
Promise
)
// Need to hack then to make sure our promise is chainable
SequelizePromise
.
prototype
.
then
=
function
(
didFulfill
,
didReject
,
didProgress
)
{
return
this
.
_then
(
didFulfill
,
didReject
,
didProgress
,
void
0
,
new
SequelizePromise
(
function
()
{}),
this
.
then
);
};
SequelizePromise
.
prototype
.
on
=
function
(
evt
,
fct
)
{
SequelizePromise
.
prototype
.
on
=
function
(
evt
,
fct
)
{
if
(
evt
===
'success'
)
{
if
(
evt
===
'success'
)
{
...
@@ -72,6 +78,7 @@ SequelizePromise.prototype.emit = function(evt) {
...
@@ -72,6 +78,7 @@ SequelizePromise.prototype.emit = function(evt) {
* @alias ok
* @alias ok
* @return this
* @return this
*/
*/
SequelizePromise
.
prototype
.
success
=
SequelizePromise
.
prototype
.
success
=
SequelizePromise
.
prototype
.
ok
=
function
(
fct
)
{
SequelizePromise
.
prototype
.
ok
=
function
(
fct
)
{
this
.
then
(
fct
);
this
.
then
(
fct
);
...
...
test/promise.test.js
View file @
6e75497
...
@@ -421,6 +421,21 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
...
@@ -421,6 +421,21 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
});
});
});
});
it
(
'should still work with .complete() after chaining'
,
function
(
done
)
{
var
spy
=
sinon
.
spy
()
,
promise
=
new
SequelizePromise
(
function
(
resolve
,
reject
)
{
resolve
(
'Heyo'
);
});
promise
.
then
(
function
(
result
)
{
return
result
+
'123'
;
}).
complete
(
function
(
err
,
result
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
result
).
to
.
equal
(
'Heyo123'
);
done
();
});
});
it
(
'should still work with .success() when emitting'
,
function
(
done
)
{
it
(
'should still work with .success() when emitting'
,
function
(
done
)
{
var
spy
=
sinon
.
spy
()
var
spy
=
sinon
.
spy
()
,
promise
=
new
SequelizePromise
(
function
(
resolve
,
reject
)
{
,
promise
=
new
SequelizePromise
(
function
(
resolve
,
reject
)
{
...
@@ -514,8 +529,8 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
...
@@ -514,8 +529,8 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
describe
(
"proxy"
,
function
()
{
describe
(
"proxy"
,
function
()
{
it
(
"should correctly work with success listeners"
,
function
(
done
)
{
it
(
"should correctly work with success listeners"
,
function
(
done
)
{
var
emitter
=
new
SequelizePromise
()
var
emitter
=
new
SequelizePromise
(
function
()
{}
)
,
proxy
=
new
SequelizePromise
()
,
proxy
=
new
SequelizePromise
(
function
()
{}
)
,
success
=
sinon
.
spy
()
,
success
=
sinon
.
spy
()
emitter
.
success
(
success
)
emitter
.
success
(
success
)
...
@@ -531,8 +546,8 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
...
@@ -531,8 +546,8 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
})
})
it
(
"should correctly work with error listeners"
,
function
(
done
)
{
it
(
"should correctly work with error listeners"
,
function
(
done
)
{
var
emitter
=
new
SequelizePromise
()
var
emitter
=
new
SequelizePromise
(
function
()
{}
)
,
proxy
=
new
SequelizePromise
()
,
proxy
=
new
SequelizePromise
(
function
()
{}
)
,
error
=
sinon
.
spy
()
,
error
=
sinon
.
spy
()
emitter
.
error
(
error
)
emitter
.
error
(
error
)
...
@@ -549,8 +564,8 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
...
@@ -549,8 +564,8 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
})
})
it
(
"should correctly work with complete/done listeners"
,
function
(
done
)
{
it
(
"should correctly work with complete/done listeners"
,
function
(
done
)
{
var
promise
=
new
SequelizePromise
()
var
promise
=
new
SequelizePromise
(
function
()
{}
)
,
proxy
=
new
SequelizePromise
()
,
proxy
=
new
SequelizePromise
(
function
()
{}
)
,
complete
=
sinon
.
spy
()
,
complete
=
sinon
.
spy
()
promise
.
complete
(
complete
)
promise
.
complete
(
complete
)
...
@@ -569,7 +584,7 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
...
@@ -569,7 +584,7 @@ describe(Support.getTestDialectTeaser("Promise"), function () {
describe
(
"when emitting an error event with an array of errors"
,
function
()
{
describe
(
"when emitting an error event with an array of errors"
,
function
()
{
describe
(
"if an error handler is given"
,
function
()
{
describe
(
"if an error handler is given"
,
function
()
{
it
(
"should return the whole array"
,
function
(
done
)
{
it
(
"should return the whole array"
,
function
(
done
)
{
var
emitter
=
new
SequelizePromise
()
var
emitter
=
new
SequelizePromise
(
function
()
{}
)
var
errors
=
[
var
errors
=
[
[
[
new
Error
(
"First error"
),
new
Error
(
"First error"
),
...
...
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