File tree Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -185,7 +185,7 @@ describe('react-most', () => {
185185 describe ( 'composable' , ( ) => {
186186 const counterWrapper2 = connect ( intent$ => {
187187 return {
188- sink2 $ : intent$ . map ( intent => {
188+ sink $ : intent$ . map ( intent => {
189189 switch ( intent . type ) {
190190 case 'inc2' :
191191 return state => ( { count :state . count + 2 } )
@@ -217,4 +217,35 @@ describe('react-most', () => {
217217 } )
218218 } )
219219
220+ describe ( 'convension default to `action` field in sinks' , ( ) => {
221+ const Counter = connect ( intent$ => {
222+ return {
223+ sink$ : intent$ . map ( intent => {
224+ switch ( intent . type ) {
225+ case 'inc3' :
226+ return state => ( { count :state . count + 3 } )
227+ default :
228+ return state => state
229+ }
230+ } ) ,
231+ actions : {
232+ inc3 : ( ) => ( { type : 'inc3' } )
233+ } ,
234+ }
235+ } ) ( CounterView )
236+
237+ it ( 'counter inc 3' , ( ) => {
238+ let counterWrapper = TestUtils . renderIntoDocument (
239+ < Most >
240+ < Counter history = { true } />
241+ </ Most >
242+ )
243+ let counter = TestUtils . findRenderedComponentWithType ( counterWrapper , Counter )
244+ dispatch ( [ { type :'inc3' } ,
245+ { type :'inc3' } ] , counter )
246+ return historyStreamOf ( counter )
247+ . take$ ( 2 )
248+ . then ( state => expect ( state . count ) . toEqual ( 6 ) )
249+ } )
250+ } )
220251} )
Original file line number Diff line number Diff line change @@ -123,11 +123,15 @@ function actionsAndSinks(sinks, self){
123123 for ( let name in sinks ) {
124124 if ( observable ( sinks [ name ] ) ) {
125125 _sinks . push ( sinks [ name ] ) ;
126- }
127- else if ( sinks [ name ] instanceof Function ) {
126+ } else if ( sinks [ name ] instanceof Function ) {
128127 _actions [ name ] = ( ...args ) => {
129128 return self . context [ INTENT_STREAM ] . send ( sinks [ name ] . apply ( self , args ) ) ;
130129 }
130+ } else if ( name === 'actions' ) {
131+ for ( let a in sinks [ name ] )
132+ _actions [ a ] = ( ...args ) => {
133+ return self . context [ INTENT_STREAM ] . send ( a . apply ( self , args ) ) ;
134+ }
131135 }
132136 }
133137 return [ _actions , _sinks ]
You can’t perform that action at this time.
0 commit comments