Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
a19c003b
Commit
a19c003b
authored
May 19, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eventManager anonymous obj
parent
01d700dc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
+11
-6
eventManager.js
src/lib/eventManager.js
+11
-6
No files found.
src/lib/eventManager.js
View file @
a19c003b
...
...
@@ -2,6 +2,7 @@
function
eventManager
()
{
this
.
registered
=
{}
this
.
anonymous
=
{}
}
/*
...
...
@@ -13,15 +14,16 @@ function eventManager () {
* @param {Func} func - function of the listenners that will be executed
*/
eventManager
.
prototype
.
unregister
=
function
(
eventName
,
obj
,
func
)
{
if
(
!
this
.
registered
[
eventName
])
{
return
}
if
(
obj
instanceof
Function
)
{
func
=
obj
obj
=
{}
obj
=
this
.
anonymous
}
for
(
var
reg
in
this
.
registered
[
eventName
])
{
if
(
this
.
registered
[
eventName
][
reg
]
&&
this
.
registered
[
eventName
][
reg
].
obj
===
obj
&&
(
!
func
||
this
.
registered
[
eventName
][
reg
].
func
===
func
))
{
if
(
this
.
registered
[
eventName
][
reg
].
obj
===
obj
&&
this
.
registered
[
eventName
][
reg
].
func
===
func
)
{
this
.
registered
[
eventName
].
splice
(
reg
,
1
)
return
}
}
}
...
...
@@ -40,7 +42,7 @@ eventManager.prototype.register = function (eventName, obj, func) {
}
if
(
obj
instanceof
Function
)
{
func
=
obj
obj
=
{}
obj
=
this
.
anonymous
}
this
.
registered
[
eventName
].
push
({
obj
:
obj
,
...
...
@@ -56,9 +58,12 @@ eventManager.prototype.register = function (eventName, obj, func) {
* @param {Array}j - argument that will be passed to the exectued function.
*/
eventManager
.
prototype
.
trigger
=
function
(
eventName
,
args
)
{
if
(
!
this
.
registered
[
eventName
])
{
return
}
for
(
var
listener
in
this
.
registered
[
eventName
])
{
var
l
=
this
.
registered
[
eventName
][
listener
]
l
.
func
.
apply
(
l
.
obj
,
args
)
l
.
func
.
apply
(
l
.
obj
===
this
.
anonymous
?
{}
:
l
.
obj
,
args
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment