-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
302c287
commit 9cdcecd
Showing
8 changed files
with
222 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
System.register([], function (_export) { | ||
"use strict"; | ||
|
||
var Handler, EventAggregator; | ||
_export("includeEventsIn", includeEventsIn); | ||
|
||
_export("install", install); | ||
|
||
function includeEventsIn(obj) { | ||
var ea = new EventAggregator(); | ||
|
||
obj.subscribe = function (event, callback) { | ||
return ea.subscribe(event, callback); | ||
}; | ||
|
||
obj.publish = function (event, data) { | ||
ea.publish(event, data); | ||
}; | ||
|
||
return ea; | ||
} | ||
|
||
function install(aurelia) { | ||
aurelia.withInstance(EventAggregator, includeEventsIn(aurelia)); | ||
} | ||
return { | ||
setters: [], | ||
execute: function () { | ||
Handler = function Handler(messageType, callback) { | ||
this.messageType = messageType; | ||
this.callback = callback; | ||
}; | ||
|
||
Handler.prototype.handle = function (message) { | ||
if (message instanceof this.messageType) { | ||
this.callback.call(null, message); | ||
} | ||
}; | ||
|
||
EventAggregator = function EventAggregator() { | ||
this.eventLookup = {}; | ||
this.messageHandlers = []; | ||
}; | ||
|
||
EventAggregator.prototype.publish = function (event, data) { | ||
var subscribers, i, handler; | ||
|
||
if (typeof event === "string") { | ||
subscribers = this.eventLookup[event]; | ||
if (subscribers) { | ||
subscribers = subscribers.slice(); | ||
i = subscribers.length; | ||
|
||
while (i--) { | ||
subscribers[i](data, event); | ||
} | ||
} | ||
} else { | ||
subscribers = this.messageHandlers.slice(); | ||
i = subscribers.length; | ||
|
||
while (i--) { | ||
subscribers[i].handle(event); | ||
} | ||
} | ||
}; | ||
|
||
EventAggregator.prototype.subscribe = function (event, callback) { | ||
var subscribers, handler; | ||
|
||
if (typeof event === "string") { | ||
subscribers = this.eventLookup[event] || (this.eventLookup[event] = []); | ||
|
||
subscribers.push(callback); | ||
|
||
return function () { | ||
subscribers.splice(subscribers.indexOf(callback), 1); | ||
}; | ||
} else { | ||
handler = new Handler(event, callback); | ||
subscribers = this.messageHandlers; | ||
|
||
subscribers.push(handler); | ||
|
||
return function () { | ||
subscribers.splice(subscribers.indexOf(handler), 1); | ||
}; | ||
} | ||
}; | ||
|
||
_export("EventAggregator", EventAggregator); | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## 0.2.0 (2015-01-06) | ||
|
||
|
||
#### Bug Fixes | ||
|
||
* **index:** remove invalid character ([96642658](http://github.com/aurelia/event-aggregator/commit/96642658caf7d90733a0e103980841ccbbc43eb8)) | ||
|
||
|
||
#### Features | ||
|
||
* **build:** update compiler and switch to register module format ([302c2870](http://github.com/aurelia/event-aggregator/commit/302c287092d9812a3d2c7e5fca2c1bb20618fffc)) | ||
* **event-aggregator:** enable plugin usage ([2c597329](http://github.com/aurelia/event-aggregator/commit/2c5973292dbd5087325226298ae966b1dcb7ac17)) | ||
|
Oops, something went wrong.