backbone-seen.js 803 Bytes
define(
    [
        'underscore',
    ],
    function(
        _
    ) {
        'use strict';

        var seen = function(attrName, wasSeen) {
            if (this._seen === undefined) {
                this._seen = {};
            }
            if (attrName === undefined) {
                return _.keys(_.clone(this._seen));
            }
            if (wasSeen) {
                this._seen[attrName] = true;
            } else if (wasSeen === false) {
                delete this._seen[attrName];
            } else {
                return this._seen[attrName];
            }
            return this;
        };

        return {
            mixin: function(modelClass) {
                modelClass.prototype.seen = seen;
                return modelClass;
            },
        };
    }
);