Plato on Github
Report Home
domRefresh.js
Maintainability
83.94
Lines of code
34
Difficulty
9.47
Estimated Errors
0.12
Function weight
By Complexity
By SLOC
// DOMRefresh // ---------- // // Monitor a view's state, and after it has been rendered and shown // in the DOM, trigger a "dom:refresh" event every time it is // re-rendered. Marionette.MonitorDOMRefresh = (function(){ // track when the view has been rendered function handleShow(view){ view._isShown = true; triggerDOMRefresh(view); } // track when the view has been shown in the DOM, // using a Marionette.Region (or by other means of triggering "show") function handleRender(view){ view._isRendered = true; triggerDOMRefresh(view); } // Trigger the "dom:refresh" event and corresponding "onDomRefresh" method function triggerDOMRefresh(view){ if (view._isShown && view._isRendered){ if (_.isFunction(view.triggerMethod)){ view.triggerMethod("dom:refresh"); } } } // Export public API return function(view){ view.listenTo(view, "show", function(){ handleShow(view); }); view.listenTo(view, "render", function(){ handleRender(view); }); }; })();