@@ -3,6 +3,17 @@ var Bacon = require('baconjs');
3
3
module . exports . BaconMixin = ( ( function ( ) {
4
4
'use strict' ;
5
5
6
+ function eventBus ( component , eventName , generator ) {
7
+ var bacon = component . _bacon = component . _bacon || { } ;
8
+ var buses = bacon [ 'buses.events' ] = bacon [ 'buses.events' ] || { } ;
9
+ var bus = buses [ eventName ] ;
10
+ if ( ! bus ) {
11
+ bus = buses [ eventName ] = new Bacon . Bus ( ) ;
12
+ component [ eventName ] = generator ( bus ) ;
13
+ }
14
+ return bus ;
15
+ }
16
+
6
17
function propsOrStateProperty ( component , allPropsOrStateKey , groupKey , filterKey ) {
7
18
var bacon = component . _bacon = component . _bacon || { } ;
8
19
var allPropertyKey = 'properties.' + allPropsOrStateKey ;
@@ -36,32 +47,25 @@ module.exports.BaconMixin = ((function(){
36
47
return propsOrStateProperty ( this , 'allState' , 'state' , stateName ) ;
37
48
} ,
38
49
eventStream : function ( eventName ) {
39
- var bacon = this . _bacon = this . _bacon || { } ;
40
- var buses = bacon [ 'buses.events' ] = bacon [ 'buses.events' ] || { } ;
41
- var bus = buses [ eventName ] ;
42
- if ( ! bus ) {
43
- bus = buses [ eventName ] = new Bacon . Bus ( ) ;
44
- this [ eventName ] = function sendEventToStream ( event ) {
45
- bus . push ( event ) ;
46
- } ;
47
- }
48
- return bus ;
50
+ return eventBus ( this , eventName , function ( bus ) {
51
+ return function sendEventToStream ( event ) { bus . push ( event ) ; } ;
52
+ } ) ;
53
+ } ,
54
+ valueStream : function ( eventName ) {
55
+ return eventBus ( this , eventName , function ( bus ) {
56
+ return function sendEventToStream ( event ) { bus . push ( event . target . value ) ; } ;
57
+ } ) ;
49
58
} ,
50
59
domEventStream : function ( eventName , prevDefault , stopPropagation ) {
51
- var bacon = this . _bacon = this . _bacon || { } ;
52
- var buses = bacon [ 'buses.events' ] = bacon [ 'buses.events' ] || { } ;
53
- var bus = buses [ eventName ] ;
54
60
if ( typeof prevDefault == "undefined" ) prevDefault = true ;
55
61
if ( typeof stopPropagation == "undefined" ) stopPropagation = true ;
56
- if ( ! bus ) {
57
- bus = buses [ eventName ] = new Bacon . Bus ( ) ;
58
- this [ eventName ] = function sendEventToStream ( event ) {
62
+ return eventBus ( this , eventName , function ( bus ) {
63
+ return function sendEventToStream ( event ) {
59
64
prevDefault && event . preventDefault ( ) ;
60
65
stopPropagation && event . stopPropagation ( ) ;
61
66
bus . push ( event ) ;
62
67
} ;
63
- }
64
- return bus ;
68
+ } ) ;
65
69
} ,
66
70
subscribeTo : function ( unsub ) {
67
71
var bacon = this . _bacon = this . _bacon || { } ;
0 commit comments