Understanding Backbone and Marionette View lifecycle

烂漫一生 提交于 2019-12-04 03:28:43

For what it's worth, I believe everything you've said is more or less correct.

Looking at the source (available here -- look for "DomRefresh") the MonitorDOMRefresh bits are mixed in to every view and add this API:

return function(view){
  view.listenTo(view, "show", function(){
    handleShow(view);
  });

  view.listenTo(view, "render", function(){
    handleRender(view);
  });
};

So really, all that's happening is the attachment of 2 event listeners to the view, and the callbacks (handleShow/handleRender) set a boolean _isShown or _isRendered and call triggerDomRefresh, which says:

function triggerDOMRefresh(view){
  if (view._isShown && view._isRendered){
    if (_.isFunction(view.triggerMethod)){
      view.triggerMethod("dom:refresh");
    }
  }
}

So, there you go... onDomRefresh will be called anytime the view has been rendered, shown, and then re-rendered.

Hope that helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!