@@ -83,15 +83,9 @@ module.exports = define = ns.define = function(objPrototype, defines, baseDefine
8383 return data ;
8484 } ) ;
8585
86- // Add necessary event methods to this object.
87- for ( var prop in eventsProto ) {
88- Object . defineProperty ( objPrototype , prop , {
89- enumerable : false ,
90- value : eventsProto [ prop ] ,
91- configurable : true ,
92- writable : true
93- } ) ;
94- }
86+ // Mixin the event methods
87+ define . mixinEvents ( objPrototype ) ;
88+
9589 // add so instance defs can be dynamically added
9690 Object . defineProperty ( objPrototype , "_define" , {
9791 enumerable : false ,
@@ -280,7 +274,7 @@ make = {
280274 if ( newVal !== current ) {
281275 setData . call ( this , newVal ) ;
282276
283- canEvent . dispatch . call ( this , {
277+ canEvent . trigger . call ( this , {
284278 type : prop ,
285279 target : this
286280 } , [ newVal , current ] ) ;
@@ -642,50 +636,12 @@ replaceWith = function(obj, prop, cb, writable) {
642636eventsProto = assign ( { } , event ) ;
643637assign ( eventsProto , {
644638 _eventSetup : function ( ) { } ,
645- _eventTeardown : function ( ) { } ,
646- addEventListener : function ( eventName , handler ) {
647-
648- var computedBinding = this . _computed && this . _computed [ eventName ] ;
649- if ( computedBinding && computedBinding . compute ) {
650- if ( ! computedBinding . count ) {
651- computedBinding . count = 1 ;
652- computedBinding . compute . addEventListener ( "change" , computedBinding . handler ) ;
653- } else {
654- computedBinding . count ++ ;
655- }
656-
657- }
658-
659- var baseAddEventListener = this . __proto__ . addEventListener ||
660- eventLifecycle . addAndSetup ;
661-
662- return baseAddEventListener . apply ( this , arguments ) ;
663- } ,
664-
665- // ### unbind
666- // Stops listening to an event.
667- // If this is the last listener of a computed property,
668- // stop forwarding events of the computed property to this map.
669- removeEventListener : function ( eventName , handler ) {
670- var computedBinding = this . _computed && this . _computed [ eventName ] ;
671- if ( computedBinding ) {
672- if ( computedBinding . count === 1 ) {
673- computedBinding . count = 0 ;
674- computedBinding . compute . removeEventListener ( "change" , computedBinding . handler ) ;
675- } else {
676- computedBinding . count -- ;
677- }
678-
679- }
680-
681- return eventLifecycle . removeAndTeardown . apply ( this , arguments ) ;
682-
683- }
639+ _eventTeardown : function ( ) { }
684640} ) ;
685- eventsProto . on = eventsProto . bind = eventsProto . addEventListener ;
686- eventsProto . off = eventsProto . unbind = eventsProto . removeEventListener ;
687641
688642delete eventsProto . one ;
643+ delete eventsProto . addEventListener ;
644+ delete eventsProto . removeEventListener ;
689645
690646define . setup = function ( props , sealed ) {
691647 defineConfigurableAndNotEnumerable ( this , "_cid" ) ;
@@ -721,6 +677,62 @@ define.setup = function(props, sealed) {
721677} ;
722678define . replaceWith = replaceWith ;
723679define . eventsProto = eventsProto ;
680+ define . mixinEvents = function ( objPrototype , makeEnumerable ) {
681+ // Add necessary event methods to this object.
682+ for ( var prop in eventsProto ) {
683+ Object . defineProperty ( objPrototype , prop , {
684+ enumerable : ! ! makeEnumerable ,
685+ value : eventsProto [ prop ] ,
686+ configurable : true ,
687+ writable : true
688+ } ) ;
689+ }
690+
691+ var baseAddEventListener = objPrototype . addEventListener ||
692+ canEvent . addEventListener ;
693+ var baseRemoveEventListener = objPrototype . removeEventListener ||
694+ canEvent . removeEventListener ;
695+
696+ objPrototype . addEventListener = function ( eventName , handler ) {
697+ var computedBinding = this . _computed && this . _computed [ eventName ] ;
698+ if ( computedBinding && computedBinding . compute ) {
699+ if ( ! computedBinding . count ) {
700+ computedBinding . count = 1 ;
701+ computedBinding . compute . addEventListener ( "change" , computedBinding . handler ) ;
702+ } else {
703+ computedBinding . count ++ ;
704+ }
705+ }
706+
707+ eventLifecycle . addAndSetup
708+
709+ return baseAddEventListener . apply ( this , arguments ) ;
710+ } ;
711+
712+ // ### unbind
713+ // Stops listening to an event.
714+ // If this is the last listener of a computed property,
715+ // stop forwarding events of the computed property to this map.
716+ objPrototype . removeEventListener = function ( eventName , handler ) {
717+ var computedBinding = this . _computed && this . _computed [ eventName ] ;
718+ if ( computedBinding ) {
719+ if ( computedBinding . count === 1 ) {
720+ computedBinding . count = 0 ;
721+ computedBinding . compute . removeEventListener ( "change" , computedBinding . handler ) ;
722+ } else {
723+ computedBinding . count -- ;
724+ }
725+
726+ }
727+
728+ return baseRemoveEventListener . apply ( this , arguments ) ;
729+ } ;
730+
731+ eventLifecycle ( objPrototype ) ;
732+
733+ objPrototype . on = objPrototype . bind = objPrototype . addEventListener ;
734+ objPrototype . off = objPrototype . unbind = objPrototype . removeEventListener ;
735+ } ;
724736define . defineConfigurableAndNotEnumerable = defineConfigurableAndNotEnumerable ;
725737define . make = make ;
726738define . getDefinitionOrMethod = getDefinitionOrMethod ;
0 commit comments