@@ -18,13 +18,13 @@ export interface TreeObject {
1818 expanded : boolean ;
1919 canExpand ?: boolean ;
2020 icon : string | null ;
21+ className : string | null ;
2122 highlight ?: boolean ;
2223}
2324
2425export interface EntryObjectExtraOptions {
2526 dynamicTitleMethod ?: DynamicTitleMethod ;
2627 staticTitleMethod ?: StaticTitleMethod ;
27- classMethod ?: ClassMethod ;
2828 isRoot ?: boolean ;
2929 parent ?: string ;
3030 isLoaded ?: boolean ;
@@ -45,11 +45,10 @@ export class EntryObject {
4545 public _attributes : EntryObjectAttributes ;
4646 public _dynamicTitleMethod : DynamicTitleMethod ;
4747 public _staticTitleMethod : StaticTitleMethod ;
48- public _classMethod : ClassMethod ;
4948
5049 @observable _title : string ;
5150 @observable _icon : string | null ;
52- @observable _class : string ;
51+ @observable _class : string | null ;
5352 @observable _selected : boolean ;
5453 @observable _parent : string ;
5554 @observable _children : string [ ] ;
@@ -67,12 +66,12 @@ export class EntryObject {
6766
6867 constructor ( opts : EntryObjectOptions , attributes : EntryObjectAttributes ) {
6968 const { mxObject, changeHandler, extraOpts } = opts ;
70- const { staticTitleMethod, dynamicTitleMethod, classMethod , isRoot, parent, isLoaded } = extraOpts ;
69+ const { staticTitleMethod, dynamicTitleMethod, isRoot, parent, isLoaded } = extraOpts ;
7170 this . _obj = mxObject ;
7271
7372 this . _title = "" ;
7473 this . _icon = null ;
75- this . _class = "" ;
74+ this . _class = null ;
7675 this . _selected = false ;
7776 this . _parent = typeof parent !== "undefined" ? parent : "" ;
7877 this . _children = [ ] ;
@@ -82,7 +81,6 @@ export class EntryObject {
8281 this . _isRoot = typeof isRoot !== "undefined" ? isRoot : false ;
8382 this . _dynamicTitleMethod = dynamicTitleMethod || null ;
8483 this . _staticTitleMethod = staticTitleMethod || null ;
85- this . _classMethod = classMethod || null ;
8684 this . _changeHandler = changeHandler || ( ( ) : void => { } ) ;
8785 this . _subscriptions = [ ] ;
8886 this . _attributes = attributes ;
@@ -97,10 +95,6 @@ export class EntryObject {
9795 this . _title = staticTitleMethod ( mxObject ) as string ;
9896 }
9997
100- if ( classMethod ) {
101- this . fixClass ( ) ;
102- }
103-
10498 this . resetSubscription ( ) ;
10599 this . setAttributes ( ) ;
106100 }
@@ -127,6 +121,10 @@ export class EntryObject {
127121 const icon = this . _obj . get ( attr . iconAttr ) as string ;
128122 this . setIcon ( icon ) ;
129123 }
124+ if ( attr . classAttr ) {
125+ const className = this . _obj . get ( attr . classAttr ) as string ;
126+ this . setClass ( className ) ;
127+ }
130128
131129 if ( attr . hasChildAttr ) {
132130 const hasChildren = this . _obj . get ( attr . hasChildAttr ) as boolean ;
@@ -141,13 +139,6 @@ export class EntryObject {
141139 this . _subscriptions = [ ] ;
142140 }
143141
144- @action
145- fixClass ( ) : void {
146- if ( this . _classMethod ) {
147- this . _class = this . _classMethod ( this . _obj ) ;
148- }
149- }
150-
151142 @action
152143 resetSubscription ( ) : void {
153144 const { subscribe } = window . mx . data ;
@@ -227,7 +218,7 @@ export class EntryObject {
227218
228219 @computed
229220 get className ( ) : string {
230- return this . _class ;
221+ return this . _class !== null ? this . _class : "" ;
231222 }
232223
233224 @computed
@@ -251,7 +242,8 @@ export class EntryObject {
251242 root : this . isRoot ,
252243 selected : this . selected ,
253244 expanded : this . isExpanded ,
254- icon : this . icon
245+ icon : this . icon ,
246+ className : this . className
255247 } ;
256248 }
257249
@@ -302,4 +294,9 @@ export class EntryObject {
302294 setIcon ( str = "" ) : void {
303295 this . _icon = str === "" ? null : str ;
304296 }
297+
298+ @action
299+ setClass ( str = "" ) : void {
300+ this . _class = str === "" ? null : str ;
301+ }
305302}
0 commit comments