function Sync(model, method, opts) { var prefix = model.config.adapter.prefix ? model.config.adapter.prefix : 'default'; var regex = new RegExp("^(" + prefix + ")\\-(\\d+)$"); if (method === 'read') { if (opts.parse) { // is collection var list = []; _.each(TAP.listProperties(), function(prop) { var match = prop.match(regex); if (match !== null) { list.push(TAP.getObject(prop)); } }); model.reset(list); var maxId = _.max(_.pluck(list, 'id')); model.maxId = (_.isFinite(maxId) ? maxId : 0) + 1; } else { // is model var obj = TAP.getObject(prefix + '-' + model.get('id')); model.set(obj); } } else if (method === 'create' || method === 'update') { TAP.setObject(prefix + '-' + model.get('id'), model.toJSON() || {}); } else if (method === 'delete') { TAP.removeProperty(prefix + '-' + model.get('id')); model.clear(); } }
function Sync(model, method, opts) { var prefix = model.config.adapter.prefix ? model.config.adapter.prefix : "default", regex = new RegExp("^(" + prefix + ")\\-(\\d+)$"); if (method === "read") if (opts.parse) { var list = []; _.each(TAP.listProperties(), function(prop) { var match = prop.match(regex); match !== null && list.push(TAP.getObject(prop)); }), model.reset(list); var maxId = _.max(_.pluck(list, "id")); model.maxId = (_.isFinite(maxId) ? maxId : 0) + 1; } else { var obj = TAP.getObject(prefix + "-" + model.get("id")); model.set(obj); } else method === "create" || method === "update" ? TAP.setObject(prefix + "-" + model.get("id"), model.toJSON() || {}) : method === "delete" && (TAP.removeProperty(prefix + "-" + model.get("id")), model.clear()); }