@@ -154,78 +154,72 @@ class EffectButton extends Component {
154154 }
155155
156156 /**
157+ * Final. Should not be overridden.
158+ * This is the core reactive effect.
157159 * @returns {Neo.core.Effect }
160+ * @protected
158161 */
159162 createVdomEffect ( ) {
160163 return new Effect ( { fn : ( ) => {
161- let me = this ;
164+ // The effect's only job is to get the config and trigger an update.
165+ this . _vdom = this . getVdomConfig ( ) ;
166+ this . update ( ) ;
167+ } } ) ;
168+ }
162169
163- // Logic from updateTag()
164- let { editRoute, route, url} = me ;
165- let link = ! editRoute && route || url ;
166- let tag = 'button' ;
167- let href = null ;
170+ /**
171+ * Builds the array of child nodes (the 'cn' property).
172+ * Subclasses can override this to add or remove children.
173+ * @returns {Object[] }
174+ * @protected
175+ */
176+ getVdomChildren ( ) {
177+ return [
178+ // iconNode
179+ { tag : 'span' , cls : [ 'neo-button-glyph' , ...this . _iconCls || [ ] ] , removeDom : ! this . iconCls , style : { color : this . iconColor || null } } ,
180+ // textNode
181+ { tag : 'span' , cls : [ 'neo-button-text' ] , id : `${ this . id } __text` , removeDom : ! this . text , text : this . text } ,
182+ // badgeNode
183+ { cls : [ 'neo-button-badge' , 'neo-' + this . badgePosition ] , removeDom : ! this . badgeText , text : this . badgeText } ,
184+ // rippleWrapper
185+ { cls : [ 'neo-button-ripple-wrapper' ] , removeDom : ! this . useRippleEffect , cn : [ { cls : [ 'neo-button-ripple' ] } ] }
186+ ] ;
187+ }
168188
169- if ( ! editRoute && route ?. startsWith ( '#' ) === false ) {
170- link = '#' + link ;
171- }
189+ /**
190+ * Builds the array of CSS classes for the root element.
191+ * @returns {String[] }
192+ * @protected
193+ */
194+ getVdomCls ( ) {
195+ let vdomCls = [ ...this . baseCls , ...this . cls ] ;
172196
173- if ( link ) {
174- href = link ;
175- tag = 'a' ;
176- }
197+ NeoArray . toggle ( vdomCls , 'no-text' , ! this . text ) ;
198+ NeoArray . toggle ( vdomCls , 'pressed' , this . pressed ) ;
199+ vdomCls . push ( 'icon-' + this . iconPosition ) ;
200+
201+ return vdomCls ;
202+ }
177203
178- // Logic from afterSetText & afterSetPressed & afterSetIconPosition
179- let vdomCls = [ ] ;
180-
181- vdomCls . push ( ...me . baseCls , ...me . cls ) ;
182-
183- NeoArray . toggle ( vdomCls , 'no-text' , ! me . text ) ;
184- NeoArray . toggle ( vdomCls , 'pressed' , me . pressed ) ;
185- vdomCls . push ( 'icon-' + me . iconPosition ) ;
186-
187- // Main vdom object
188- me . _vdom = {
189- tag,
190- cls : vdomCls ,
191- href,
192- target : me . url ? me . urlTarget : null ,
193- type : tag === 'button' ? 'button' : null ,
194- cn : [
195- // iconNode from afterSetIconCls & afterSetIconColor
196- {
197- tag : 'span' ,
198- cls : [ 'neo-button-glyph' , ...me . _iconCls || [ ] ] ,
199- removeDom : ! me . iconCls ,
200- style : { color : me . iconColor || null }
201- } ,
202- // textNode from afterSetText & afterSetId
203- {
204- tag : 'span' ,
205- cls : [ 'neo-button-text' ] ,
206- id : `${ me . id } __text` ,
207- removeDom : ! me . text ,
208- text : me . text
209- } ,
210- // badgeNode from afterSetBadgeText & afterSetBadgePosition
211- {
212- cls : [ 'neo-button-badge' , 'neo-' + me . badgePosition ] ,
213- removeDom : ! me . badgeText ,
214- text : me . badgeText
215- } ,
216- // rippleWrapper from afterSetUseRippleEffect
217- {
218- cls : [ 'neo-button-ripple-wrapper' ] ,
219- removeDom : ! me . useRippleEffect ,
220- cn : [
221- { cls : [ 'neo-button-ripple' ] }
222- ]
223- }
224- ]
225- } ;
226-
227- me . update ( )
228- } } )
204+ /**
205+ * Builds the top-level VDOM object.
206+ * Subclasses can override this to add or modify root properties.
207+ * @returns {Object }
208+ * @protected
209+ */
210+ getVdomConfig ( ) {
211+ let me = this ,
212+ link = ! me . editRoute && me . route || me . url ,
213+ tag = link ? 'a' : 'button' ;
214+
215+ return {
216+ tag,
217+ cls : this . getVdomCls ( ) ,
218+ href : link ? ( link . startsWith ( '#' ) ? link : '#' + link ) : null ,
219+ target : me . url ? me . urlTarget : null ,
220+ type : tag === 'button' ? 'button' : null ,
221+ cn : this . getVdomChildren ( )
222+ } ;
229223 }
230224
231225 /**
0 commit comments