This implementation is extremely unclear and could easily be considered to be working "by accident" - especially since it will end up invoking one of "showPanel" or "hidePanel" even if there has been no change in the model state. This is also a nonstandard signature for a function named "refreshView" even if it is hidden from the point of view of the invoker of the same name. This function should be refactored into two separate functions with separate responsibilities - one to update the state of the model, and another to update the state of the UI with respect to the model ("refreshView" proper). It is not the business of a refreshView function to cause or otherwise process changes in model state.