@@ -37,52 +37,45 @@ class InputTags {
3737 return tag [ this . displayProperty ] ;
3838 }
3939
40- addTag ( tag ) {
40+ isTagValid ( tag ) {
4141 const tagText = this . getTagText ( tag ) ;
4242 const key = this . keyProperty || this . displayProperty ;
43- const valid = tagText &&
43+ return tagText &&
4444 this . tags . length <= this . maxLength &&
4545 ! this . tags . some ( element => element [ key ] === tag [ key ] ) ;
46+ }
4647
47- if ( this . onTagAdding ) {
48- this . onTagAdding ( tag ) ;
49- }
48+ addTag ( tag ) {
49+ const valid = this . isTagValid ( tag ) ;
50+
51+ this . emit ( 'onTagAdding' , tag ) ;
5052
5153 if ( valid ) {
5254 this . tags . push ( tag ) ;
5355
54- if ( this . onTagAdded ) {
55- this . onTagAdded ( tag ) ;
56- }
57- } else if ( this . onTagAddFailed ) {
58- this . onTagAddFailed ( tag ) ;
56+ this . emit ( 'onTagAdded' , tag ) ;
57+ } else {
58+ this . emit ( 'onTagAddFailed' , tag ) ;
5959 }
6060
6161 return tag ;
6262 }
6363
6464 removeTag ( tag ) {
65- if ( this . onTagRemoving ) {
66- this . onTagRemoving ( tag ) ;
67- }
65+ this . emit ( 'onTagRemoving' , tag ) ;
6866
6967 for ( let i = this . tags . length - 1 ; i >= 0 ; i -- ) {
7068 if ( this . tags [ i ] . code === tag . code ) {
7169 this . tags . splice ( i , 1 ) ;
7270 }
7371 }
7472
75- if ( this . onTagRemoved ) {
76- this . onTagRemoved ( tag ) ;
77- }
78-
73+ this . emit ( 'onTagRemoved' , tag ) ;
7974 return tag ;
8075 }
8176
8277 inputChange ( ) {
83- if ( this . inputChanged ) {
84- this . inputChanged ( this . inputSearch ) ;
85- }
78+ this . emit ( 'inputChanged' , this . inputSearch ) ;
8679 }
8780
8881 triggerFocus ( ) {
@@ -114,6 +107,12 @@ class InputTags {
114107 this . path [ this . path . length - 1 ] :
115108 this . suggestions ;
116109 }
110+
111+ emit ( action , ...params ) {
112+ if ( this [ action ] && typeof this [ action ] === 'function' ) {
113+ this [ action ] . apply ( this , params ) ;
114+ }
115+ }
117116}
118117
119118const InputTagsComponent = {
0 commit comments