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); } }); } });
initialize: function() { Manager.__super__.initialize.apply(this, arguments); this.settings = {}; this.schemas = new (Collection.extend({ model: Schema })); },
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;