-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.js
52 lines (40 loc) · 1.4 KB
/
event.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
include.module( 'event', [ 'vue', 'util' ], function () {
function Event ( events ) {
this.dispatcher = new Vue()
}
SMK.TYPE.Event = Event
Event.prototype.catchExceptions = true
Event.prototype.destroy = function () {
this.dispatcher.$off()
}
Event.define = function ( names ) {
var subclass = function() {
Event.prototype.constructor.call( this )
}
$.extend( subclass.prototype, Event.prototype )
names.forEach( function ( n ) {
subclass.prototype[ n ] = function ( handler ) {
if ( $.isFunction( handler ) ) {
this.dispatcher.$on( n, handler )
return this
}
var args = [].slice.call( arguments )
args.unshift( n )
try {
this.dispatcher.$emit.apply( this.dispatcher, args )
}
catch ( err ) {
if ( this.catchExceptions ) {
console.warn( 'Exception caught in ' + n + ' event handler:', err )
}
else {
err.message = 'Exception caught in ' + n + ' event handler: ' + err.message
throw err
}
}
return this
}
} )
return subclass
}
} )