File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ function handleEvent(event: Event) {
7373
7474type Binding = { type : string ; tag : string ; method : string }
7575function * bindings ( el : Element ) : Iterable < Binding > {
76- for ( const action of ( el . getAttribute ( 'data-action' ) || '' ) . split ( ' ' ) ) {
76+ for ( const action of ( el . getAttribute ( 'data-action' ) || '' ) . trim ( ) . split ( / \s + / ) ) {
7777 const eventSep = action . lastIndexOf ( ':' )
7878 const methodSep = action . lastIndexOf ( '#' )
7979 const type = action . slice ( 0 , eventSep )
Original file line number Diff line number Diff line change @@ -106,6 +106,22 @@ describe('bind', () => {
106106 expect ( calls ) . to . have . nested . property ( '[1][0].type' , 'submit' )
107107 } )
108108
109+ it ( 'can bind multiple actions separated by line feed' , ( ) => {
110+ const instance = document . createElement ( 'bind-test-element' )
111+ chai . spy . on ( instance , 'foo' )
112+ chai . spy . on ( instance , 'bar' )
113+ const el = document . createElement ( 'div' )
114+ el . setAttribute ( 'data-action' , `click:bind-test-element#foo\nclick:bind-test-element#bar` )
115+ instance . appendChild ( el )
116+ bind ( instance )
117+ expect ( instance . foo ) . to . have . not . been . called ( )
118+ el . dispatchEvent ( new CustomEvent ( 'click' ) )
119+ expect ( instance . foo ) . to . have . been . called . exactly ( 1 )
120+ expect ( instance . bar ) . to . have . been . called . exactly ( 1 )
121+ expect ( instance . foo . __spy . calls ) . to . have . nested . property ( '[0][0].type' , 'click' )
122+ expect ( instance . bar . __spy . calls ) . to . have . nested . property ( '[0][0].type' , 'click' )
123+ } )
124+
109125 it ( 'can bind multiple elements to the same event' , ( ) => {
110126 const instance = document . createElement ( 'bind-test-element' )
111127 chai . spy . on ( instance , 'foo' )
You can’t perform that action at this time.
0 commit comments