forked from josephg/ShareJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made my own version of microevent in coffee. doc.subscribe -> doc.on …
…like in node.
- Loading branch information
Showing
20 changed files
with
216 additions
and
350 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,32 @@ | ||
# This is a simple port of microevent.js to Coffeescript. I've changed the | ||
# function names to be consistent with node.js EventEmitter. | ||
# | ||
# microevent.js is copyright Jerome Etienne, and licensed under the MIT license: | ||
# https://github.com/jeromeetienne/microevent.js | ||
|
||
class MicroEvent | ||
on: (event, fct) -> | ||
@_events ||= {} | ||
@_events[event] ||= [] | ||
@_events[event].push(fct) | ||
this | ||
|
||
removeListener: (event, fct) -> | ||
@_events ||= {} | ||
idx = @_events[event]?.indexOf fct | ||
@_events[event].splice(idx, 1) if idx? and idx >= 0 | ||
this | ||
|
||
emit: (event, args...) -> | ||
return this unless @_events?[event] | ||
fn.apply this, args for fn in @_events[event] | ||
this | ||
|
||
# mixin will delegate all MicroEvent.js function in the destination object | ||
MicroEvent.mixin = (obj) -> | ||
proto = obj.prototype || obj | ||
proto[fname] = MicroEvent.prototype[fname] for fname in ['on', 'removeListener', 'emit'] | ||
obj | ||
|
||
module.exports = MicroEvent if module?.exports | ||
|
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
Oops, something went wrong.