Search code examples
backbone.jsviewmarionette

marionette.js view difference between onShow vs onRender?


I am new to Marionette.js and while I am refactoring my existing Backbone.js code, I noticed there are two callbacks on Marionette view (itemview) that looked to me similar, i.e. onRender and onShow. What is the difference and better way of using them ?

However, looking at source code, i think both "render" and "show" events are raised inside "view initialize".

constructor: function(){
    _.bindAll(this, "render");

    var args = Array.prototype.slice.apply(arguments);
    Backbone.View.prototype.constructor.apply(this, args);

    Marionette.MonitorDOMRefresh(this);
    this.listenTo(this, "show", this.onShowCalled, this);
}

Solution

  • onShow : view itself doesn't trigger 'show' event. It triggers by a region. So it will not be called in some cases.

    onRender : this method executes every time the view is rendered.