Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 719 Bytes

README.md

File metadata and controls

30 lines (22 loc) · 719 Bytes

Backbone ViewState

To use for Backbone.Views, the ViewState keeps data/attributes in a Backbone.View you don't want in your Backbone.Model.

Instead of using the View itself to keep data, a ViewState is the place where you set/get all attributes. All ViewState attributes are passed to your render's template as template data.

For example in some Backbone.View:

    initialize: function() {
      this.viewState = new Backbone.ViewState();
    },

    getTemplateData: function() {
      return _.extend(
        this.model.toJSON(),
        this.viewState.getAttributes()
      );
    },

    render: function() {
      this.el.html(template(this.getTemplateData()));
    }