Skip to content

Instantly share code, notes, and snippets.

@cmwelsh
Created June 15, 2013 00:53

Revisions

  1. cmwelsh created this gist Jun 15, 2013.
    18 changes: 18 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    this.listenTo(this.model, 'change', this._onModelChange);

    initialize: function()
    {
    // Only save every second at most
    this._save = _.debounce(this._save, 1000);
    },

    _onModelChange: function()
    {
    this._updateTotals();
    this._save();
    },

    _save: _.throttle(function()
    {
    this.model.save()
    }, 1000),