blackhydrogen / noop-sewi

Sana Encounter Web Interface (SEWI)
0 stars 1 forks source link

Duplicated code in tab.js making it hard to read/maintain/debug #182

Open weitsang opened 9 years ago

weitsang commented 9 years ago

I think much of the code in tab.js can be simplified and express succinctly, with the use of tables that map position to functions and to CSS.

For instance, updatePanel always add a new CSS class that corresponds to new position and remove old CSS class that corresponds to oldPosition. So, only two arguments are really needed, if we predefined a mapping from TAB_PANEL_POSITION to TAB_PANEL_STATE_CSS_CLASS.

Another example is onResourceViewerClose(). If there is a mapping from TAB_PANEL_POSITION to onResourceViewerXXX methods, then the method essentially reduces to 7 lines.

     if (this.state == sewi.constants.TAB_PANEL_POSITIONS.FULL){
            this.tab.addDropArea();
            removeSelf.call(this);
     } else {
            resourceViewerCloseCallback[this.state].call(this);
            removeSelf.call(this);
     }
lebeier commented 9 years ago

I guess thats right. should have generalized them after I have abstracted. totally overlooked on this portion.