コード例 #1
0
ファイル: packages.js プロジェクト: OverflowCreative/codebox
var Packages = Collection.extend({
    model: Package,

    // Get packages list from backend
    listAll: function() {
        return rpc.execute("packages/list")
        .then(this.reset.bind(this));
    },

    // Load all plugins from backend
    loadAll: function() {
        var that = this;
        var errors = [];

        return this.listAll()
        .then(function() {
            return that.reduce(function(prev, pkg) {
                errors = errors.concat(_.map(pkg.get("errors"), function(e) {
                    return {
                        'name': pkg.get("name"),
                        'error': e
                    };
                }));

                return prev.then(pkg.load.bind(pkg))
                .fail(function(err) {
                    errors.push({
                        'name': pkg.get("name"),
                        'error': err
                    });
                    return Q();
                });
            }, Q());
        })
        .then(function() {
            if (errors.length > 0) {
                var e = new Error("Error loading packages");
                e.errors = errors;
                return Q.reject(e);
            }
        });
    }
});
コード例 #2
0
ファイル: settings.js プロジェクト: CodeWire/codebox-1
    initialize: function() {
        Manager.__super__.initialize.apply(this, arguments);

        this.settings = {};
        this.schemas = new (Collection.extend({ model: Schema }));
    },
コード例 #3
0
ファイル: todos.js プロジェクト: HappyRhino/example
var Collection = require("hr.collection");
var storage = require("hr.storage");

var Todo = require("../models/todo");

// Key to store todos in localstorage
var STORAGE_KEY = "todos";

var Todos = Collection.extend({
    model: Todo,

    initialize: function() {
        Todos.__super__.initialize.apply(this, arguments);

        // Save collection when change
        this.listenTo(this, "change add remove", this.saveInStorage);
    },

    loadFromStorage: function() {
        this.reset(storage.get(STORAGE_KEY) || []);
    },
    saveInStorage: function() {
        storage.set(STORAGE_KEY, this.toJSON());
    }
});

module.exports = Todos;