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 f62fdefb
authored
Oct 09, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow partially proxying emitters
1 parent
99aba088
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
12 deletions
lib/emitters/custom-event-emitter.js
lib/emitters/custom-event-emitter.js
View file @
f62fdef
...
...
@@ -3,20 +3,19 @@ var util = require("util")
,
Promise
=
require
(
"promise"
)
,
proxyEventKeys
=
[
'success'
,
'error'
,
'sql'
]
,
tick
=
(
typeof
setImmediate
!==
"undefined"
?
setImmediate
:
process
.
nextTick
)
,
Utils
=
require
(
'../utils'
)
var
bindToProcess
=
function
(
fct
)
{
if
(
fct
)
{
if
(
process
.
domain
)
{
return
process
.
domain
.
bind
(
fct
);
}
if
(
fct
&&
process
.
domain
)
{
return
process
.
domain
.
bind
(
fct
)
}
return
fct
;
return
fct
};
module
.
exports
=
(
function
()
{
var
CustomEventEmitter
=
function
(
fct
)
{
this
.
fct
=
bindToProcess
(
fct
)
;
this
.
fct
=
bindToProcess
(
fct
)
}
util
.
inherits
(
CustomEventEmitter
,
EventEmitter
)
...
...
@@ -54,25 +53,40 @@ module.exports = (function() {
return
this
}
CustomEventEmitter
.
prototype
.
sql
=
function
(
fct
)
{
CustomEventEmitter
.
prototype
.
sql
=
function
(
fct
)
{
this
.
on
(
'sql'
,
bindToProcess
(
fct
))
return
this
;
}
CustomEventEmitter
.
prototype
.
proxy
=
function
(
emitter
)
{
proxyEventKeys
.
forEach
(
function
(
eventKey
)
{
/**
* Proxy every event of this custom event emitter to another one.
*
* @param {CustomEventEmitter} emitter The event emitter that should receive the events.
* @return {void}
*/
CustomEventEmitter
.
prototype
.
proxy
=
function
(
emitter
,
options
)
{
options
=
Utils
.
_
.
extend
({
keys
:
proxyEventKeys
,
skipKeys
:
[]
},
options
||
{})
options
.
keys
=
Utils
.
_
.
difference
(
options
.
keys
,
options
.
skipKeys
)
options
.
keys
.
forEach
(
function
(
eventKey
)
{
this
.
on
(
eventKey
,
function
(
result
)
{
emitter
.
emit
(
eventKey
,
result
)
})
}.
bind
(
this
))
return
this
}
CustomEventEmitter
.
prototype
.
then
=
function
(
onFulfilled
,
onRejected
)
{
CustomEventEmitter
.
prototype
.
then
=
function
(
onFulfilled
,
onRejected
)
{
var
self
=
this
onFulfilled
=
bindToProcess
(
onFulfilled
)
onRejected
=
bindToProcess
(
onRejected
)
return
new
Promise
(
function
(
resolve
,
reject
)
{
self
.
on
(
'error'
,
reject
)
.
on
(
'success'
,
resolve
);
...
...
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