function S4(){return(0|65536*(1+Math.random())).toString(16).substring(1)}function guid(){return S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()}function InitAdapter(){}function Sync(e,t,r){function o(e){localStorage.setItem(n,JSON.stringify(e))}var n=t.config.adapter.collection_name,a=t.config.data,i=null;switch(e){case"create":t.id||(t.id=guid(),t.set(t.idAttribute,t.id)),a[t.id]=t,o(a),i=t.toJSON();break;case"read":var c=localStorage.getItem(n),d=c&&JSON.parse(c)||{},s=0;for(var u in d){var l=new t.config.Model(d[u]);t.models.push(l),s++}t.length=s,i=1===s?t.models[0]:t.models;break;case"update":a[t.id]=t,o(a),i=t.toJSON();break;case"delete":delete a[t.id],o(a),i=t.toJSON()}i?(_.isFunction(r.success)&&r.success(i),"read"===e&&t.trigger("fetch")):_.isFunction(r.error)&&r.error(i)}var _=require("alloy/underscore")._;module.exports.sync=Sync,module.exports.beforeModelCreate=function(e){return e=e||{},e.data={},InitAdapter(),e},module.exports.afterModelCreate=function(e){return e=e||{},e.prototype.config.Model=e,e};