Modules (188)

ViewStateManager

Description

ViewStateManager is a singleton for views to park their global viwe state. The state is saved with project data but the View or View Factory is responsible for restoring the view state when the view is created.

Views should implement getViewState() so that the view state can be saved and that data is cached for later use.

Views or View Factories are responsible for restoring the view state when the view of that file is created by recalling the cached state. Views determine what data is store in the view state and how to restore it.

Dependencies

Variables

Private

_viewStateCache

The view state cache.

Type
Object.<string, *>
    var _viewStateCache = {};

Functions

Private

_setViewState

Sets the view state for the specfied file

file non-nullable File
the file to record the view state for
viewState nullable *
any data that the view needs to restore the view state.
    function _setViewState(file, viewState) {
        _viewStateCache[file.fullPath] = viewState;
    }
Public API

addViewStates

adds an array of view states

viewStates non-nullable object.<string, *>
View State object to append to the current set of view states
    function addViewStates(viewStates) {
        _viewStateCache = _.extend(_viewStateCache, viewStates);
    }
Public API

getViewState

gets the view state for the specified file

file non-nullable File
the file to record the view state for
Returns: ?*
whatever data that was saved earlier with a call setViewState
    function getViewState(file) {
        return _viewStateCache[file.fullPath];
    }
Public API

reset

resets the view state cache

    function reset() {
        _viewStateCache = {};
    }
Public API

updateViewState

Updates the view state for the specified view

view non-nullable {!getFile:function():File, getViewState:function():*}
the to save state
viewState nullable *
any data that the view needs to restore the view state.
    function updateViewState(view) {
        if (view.getViewState) {
            _setViewState(view.getFile(), view.getViewState());
        }
    }