10 __coverage__['build/model-sync-local/model-sync-local.js'] = {"path":"build/model-sync-local/model-sync-local.js","s":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0,0,0],"13":[0,0],"14":[0,0],"15":[0,0],"16":[0,0],"17":[0,0],"18":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0},"fnMap":{"1":{"name":"(anonymous_1)","line":1,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":47}}},"2":{"name":"LocalSync","line":34,"loc":{"start":{"line":34,"column":0},"end":{"line":34,"column":21}}},"3":{"name":"(anonymous_3)","line":58,"loc":{"start":{"line":58,"column":30},"end":{"line":58,"column":42}}},"4":{"name":"(anonymous_4)","line":116,"loc":{"start":{"line":116,"column":17},"end":{"line":116,"column":35}}},"5":{"name":"(anonymous_5)","line":153,"loc":{"start":{"line":153,"column":49},"end":{"line":153,"column":65}}},"6":{"name":"(anonymous_6)","line":186,"loc":{"start":{"line":186,"column":10},"end":{"line":186,"column":47}}},"7":{"name":"(anonymous_7)","line":230,"loc":{"start":{"line":230,"column":16},"end":{"line":230,"column":31}}},"8":{"name":"(anonymous_8)","line":244,"loc":{"start":{"line":244,"column":12},"end":{"line":244,"column":24}}},"9":{"name":"(anonymous_9)","line":256,"loc":{"start":{"line":256,"column":11},"end":{"line":256,"column":23}}},"10":{"name":"(anonymous_10)","line":268,"loc":{"start":{"line":268,"column":13},"end":{"line":268,"column":25}}},"11":{"name":"(anonymous_11)","line":289,"loc":{"start":{"line":289,"column":13},"end":{"line":289,"column":25}}},"12":{"name":"(anonymous_12)","line":306,"loc":{"start":{"line":306,"column":14},"end":{"line":306,"column":26}}},"13":{"name":"(anonymous_13)","line":320,"loc":{"start":{"line":320,"column":11},"end":{"line":320,"column":23}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":335,"column":56}},"2":{"start":{"line":34,"column":0},"end":{"line":34,"column":23}},"3":{"start":{"line":47,"column":0},"end":{"line":47,"column":36}},"4":{"start":{"line":58,"column":0},"end":{"line":78,"column":21}},"5":{"start":{"line":59,"column":4},"end":{"line":60,"column":24}},"6":{"start":{"line":62,"column":4},"end":{"line":68,"column":5}},"7":{"start":{"line":63,"column":8},"end":{"line":63,"column":31}},"8":{"start":{"line":64,"column":8},"end":{"line":64,"column":28}},"9":{"start":{"line":65,"column":8},"end":{"line":65,"column":20}},"10":{"start":{"line":67,"column":8},"end":{"line":67,"column":21}},"11":{"start":{"line":89,"column":0},"end":{"line":89,"column":22}},"12":{"start":{"line":91,"column":0},"end":{"line":328,"column":2}},"13":{"start":{"line":117,"column":8},"end":{"line":117,"column":24}},"14":{"start":{"line":119,"column":8},"end":{"line":119,"column":32}},"15":{"start":{"line":121,"column":8},"end":{"line":123,"column":9}},"16":{"start":{"line":122,"column":12},"end":{"line":122,"column":42}},"17":{"start":{"line":128,"column":8},"end":{"line":130,"column":9}},"18":{"start":{"line":129,"column":12},"end":{"line":129,"column":50}},"19":{"start":{"line":132,"column":8},"end":{"line":136,"column":9}},"20":{"start":{"line":133,"column":12},"end":{"line":133,"column":53}},"21":{"start":{"line":134,"column":12},"end":{"line":134,"column":52}},"22":{"start":{"line":140,"column":8},"end":{"line":148,"column":9}},"23":{"start":{"line":141,"column":12},"end":{"line":145,"column":13}},"24":{"start":{"line":142,"column":16},"end":{"line":142,"column":65}},"25":{"start":{"line":144,"column":16},"end":{"line":144,"column":48}},"26":{"start":{"line":147,"column":12},"end":{"line":147,"column":76}},"27":{"start":{"line":152,"column":8},"end":{"line":152,"column":74}},"28":{"start":{"line":153,"column":8},"end":{"line":158,"column":17}},"29":{"start":{"line":154,"column":12},"end":{"line":154,"column":29}},"30":{"start":{"line":155,"column":12},"end":{"line":157,"column":13}},"31":{"start":{"line":156,"column":16},"end":{"line":156,"column":55}},"32":{"start":{"line":187,"column":8},"end":{"line":187,"column":34}},"33":{"start":{"line":188,"column":8},"end":{"line":188,"column":32}},"34":{"start":{"line":190,"column":8},"end":{"line":211,"column":9}},"35":{"start":{"line":191,"column":12},"end":{"line":208,"column":13}},"36":{"start":{"line":193,"column":20},"end":{"line":197,"column":21}},"37":{"start":{"line":194,"column":24},"end":{"line":194,"column":56}},"38":{"start":{"line":196,"column":24},"end":{"line":196,"column":55}},"39":{"start":{"line":198,"column":20},"end":{"line":198,"column":26}},"40":{"start":{"line":200,"column":20},"end":{"line":200,"column":53}},"41":{"start":{"line":201,"column":20},"end":{"line":201,"column":26}},"42":{"start":{"line":203,"column":20},"end":{"line":203,"column":53}},"43":{"start":{"line":204,"column":20},"end":{"line":204,"column":26}},"44":{"start":{"line":206,"column":20},"end":{"line":206,"column":54}},"45":{"start":{"line":207,"column":20},"end":{"line":207,"column":26}},"46":{"start":{"line":210,"column":12},"end":{"line":210,"column":38}},"47":{"start":{"line":213,"column":8},"end":{"line":219,"column":9}},"48":{"start":{"line":214,"column":12},"end":{"line":214,"column":37}},"49":{"start":{"line":215,"column":15},"end":{"line":219,"column":9}},"50":{"start":{"line":216,"column":12},"end":{"line":216,"column":32}},"51":{"start":{"line":218,"column":12},"end":{"line":218,"column":55}},"52":{"start":{"line":231,"column":8},"end":{"line":231,"column":33}},"53":{"start":{"line":245,"column":8},"end":{"line":245,"column":42}},"54":{"start":{"line":257,"column":8},"end":{"line":257,"column":67}},"55":{"start":{"line":269,"column":8},"end":{"line":271,"column":48}},"56":{"start":{"line":273,"column":8},"end":{"line":273,"column":45}},"57":{"start":{"line":274,"column":8},"end":{"line":274,"column":24}},"58":{"start":{"line":275,"column":8},"end":{"line":275,"column":30}},"59":{"start":{"line":277,"column":8},"end":{"line":277,"column":21}},"60":{"start":{"line":278,"column":8},"end":{"line":278,"column":20}},"61":{"start":{"line":290,"column":8},"end":{"line":290,"column":42}},"62":{"start":{"line":291,"column":8},"end":{"line":291,"column":48}},"63":{"start":{"line":293,"column":8},"end":{"line":293,"column":21}},"64":{"start":{"line":294,"column":8},"end":{"line":294,"column":20}},"65":{"start":{"line":307,"column":8},"end":{"line":307,"column":48}},"66":{"start":{"line":308,"column":8},"end":{"line":308,"column":21}},"67":{"start":{"line":309,"column":8},"end":{"line":309,"column":29}},"68":{"start":{"line":321,"column":8},"end":{"line":326,"column":9}},"69":{"start":{"line":322,"column":12},"end":{"line":325,"column":14}},"70":{"start":{"line":332,"column":0},"end":{"line":332,"column":43}}},"branchMap":{"1":{"line":119,"type":"binary-expr","locations":[{"start":{"line":119,"column":8},"end":{"line":119,"column":14}},{"start":{"line":119,"column":19},"end":{"line":119,"column":30}}]},"2":{"line":121,"type":"if","locations":[{"start":{"line":121,"column":8},"end":{"line":121,"column":8}},{"start":{"line":121,"column":8},"end":{"line":121,"column":8}}]},"3":{"line":122,"type":"binary-expr","locations":[{"start":{"line":122,"column":24},"end":{"line":122,"column":35}},{"start":{"line":122,"column":39},"end":{"line":122,"column":41}}]},"4":{"line":128,"type":"if","locations":[{"start":{"line":128,"column":8},"end":{"line":128,"column":8}},{"start":{"line":128,"column":8},"end":{"line":128,"column":8}}]},"5":{"line":128,"type":"binary-expr","locations":[{"start":{"line":128,"column":12},"end":{"line":128,"column":22}},{"start":{"line":128,"column":26},"end":{"line":128,"column":36}},{"start":{"line":128,"column":40},"end":{"line":128,"column":65}}]},"6":{"line":132,"type":"if","locations":[{"start":{"line":132,"column":8},"end":{"line":132,"column":8}},{"start":{"line":132,"column":8},"end":{"line":132,"column":8}}]},"7":{"line":140,"type":"if","locations":[{"start":{"line":140,"column":8},"end":{"line":140,"column":8}},{"start":{"line":140,"column":8},"end":{"line":140,"column":8}}]},"8":{"line":147,"type":"binary-expr","locations":[{"start":{"line":147,"column":12},"end":{"line":147,"column":38}},{"start":{"line":147,"column":43},"end":{"line":147,"column":74}}]},"9":{"line":152,"type":"binary-expr","locations":[{"start":{"line":152,"column":8},"end":{"line":152,"column":35}},{"start":{"line":152,"column":40},"end":{"line":152,"column":72}}]},"10":{"line":155,"type":"if","locations":[{"start":{"line":155,"column":12},"end":{"line":155,"column":12}},{"start":{"line":155,"column":12},"end":{"line":155,"column":12}}]},"11":{"line":187,"type":"binary-expr","locations":[{"start":{"line":187,"column":8},"end":{"line":187,"column":15}},{"start":{"line":187,"column":20},"end":{"line":187,"column":32}}]},"12":{"line":191,"type":"switch","locations":[{"start":{"line":192,"column":16},"end":{"line":198,"column":26}},{"start":{"line":199,"column":16},"end":{"line":201,"column":26}},{"start":{"line":202,"column":16},"end":{"line":204,"column":26}},{"start":{"line":205,"column":16},"end":{"line":207,"column":26}}]},"13":{"line":193,"type":"if","locations":[{"start":{"line":193,"column":20},"end":{"line":193,"column":20}},{"start":{"line":193,"column":20},"end":{"line":193,"column":20}}]},"14":{"line":213,"type":"if","locations":[{"start":{"line":213,"column":8},"end":{"line":213,"column":8}},{"start":{"line":213,"column":8},"end":{"line":213,"column":8}}]},"15":{"line":215,"type":"if","locations":[{"start":{"line":215,"column":15},"end":{"line":215,"column":15}},{"start":{"line":215,"column":15},"end":{"line":215,"column":15}}]},"16":{"line":257,"type":"binary-expr","locations":[{"start":{"line":257,"column":15},"end":{"line":257,"column":58}},{"start":{"line":257,"column":62},"end":{"line":257,"column":66}}]},"17":{"line":321,"type":"if","locations":[{"start":{"line":321,"column":8},"end":{"line":321,"column":8}},{"start":{"line":321,"column":8},"end":{"line":321,"column":8}}]},"18":{"line":322,"type":"binary-expr","locations":[{"start":{"line":322,"column":12},"end":{"line":322,"column":24}},{"start":{"line":322,"column":28},"end":{"line":325,"column":13}}]}},"code":["(function () { YUI.add('model-sync-local', function (Y, NAME) {","","/*","An extension which provides a sync implementation through locally stored","key value pairs, either through the HTML localStorage API or falling back","onto an in-memory cache, that can be mixed into a Model or ModelList subclass.","","@module app","@submodule model-sync-local","@since 3.13.0","**/","","/**","An extension which provides a sync implementation through locally stored","key value pairs, either through the HTML localStorage API or falling back","onto an in-memory cache, that can be mixed into a Model or ModelList subclass.","","A group of Models/ModelLists is serialized in localStorage by either its","class name, or a specified 'root' that is provided.",""," var User = Y.Base.create('user', Y.Model, [Y.ModelSync.Local], {"," root: 'user'"," });",""," var Users = Y.Base.create('users', Y.ModelList, [Y.ModelSync.Local], {"," model: User,"," });","","@class ModelSync.Local","@extensionfor Model","@extensionfor ModelList","@since 3.13.0","**/","function LocalSync() {}","","/**","Properties that shouldn't be turned into ad-hoc attributes when passed to a","Model or ModelList constructor.","","@property _NON_ATTRS_CFG","@type Array","@default ['root']","@static","@protected","@since 3.13.0","**/","LocalSync._NON_ATTRS_CFG = ['root'];","","/**","Feature testing for `localStorage` availability.","Will return falsey for browsers with `localStorage`, but that don't","actually work, such as iOS Safari in private browsing mode.","","@property _hasLocalStorage","@type Boolean","@private","**/","LocalSync._hasLocalStorage = (function () {"," var LS = Y.config.win.localStorage,"," test = Y.guid();",""," try {"," LS.setItem(test, test);"," LS.removeItem(test);"," return true;"," } catch (e) {"," return false;"," }","})(),","","/**","Object of key/value pairs to fall back on when localStorage is not available.","","@property _data","@type Object","@private","**/","LocalSync._data = {};","","/**","Cache to quickly access a specific object with a given ID.","This maps a model's ID to its reference inside of `LocalSync._data`.","","@property _idMap","@type Object","@private","**/","","LocalSync._idMap = {};","","LocalSync.prototype = {",""," // -- Public Methods -------------------------------------------------------"," "," /**"," Root used as the key inside of localStorage and/or the in-memory store."," "," @property root"," @type String"," @default \"\""," @since 3.13.0"," **/"," root: '',",""," /**"," Shortcut for access to localStorage."," "," @property storage"," @type Storage"," @default null"," @since 3.13.0"," **/"," storage: null,",""," // -- Lifecycle Methods -----------------------------------------------------"," initializer: function (config) {"," var store, data;",""," config || (config = {});",""," if ('root' in config) {"," this.root = config.root || '';"," }",""," // This is checking to see if the sync layer is being applied to"," // a ModelList, and if so, is looking for a `root` property on its"," // Model's prototype instead."," if (!this.root && this.model && this.model.prototype.root) {"," this.root = this.model.prototype.root;"," }",""," if (LocalSync._hasLocalStorage) {"," this.storage = Y.config.win.localStorage;"," store = this.storage.getItem(this.root);"," } else {"," }",""," // Pull in existing data from localStorage, if possible."," // Otherwise, see if there's existing data on the local cache."," if (store) {"," try {"," LocalSync._data[this.root] = Y.JSON.parse(store);"," } catch (e) {"," LocalSync._data[this.root] = [];"," }"," } else {"," LocalSync._data[this.root] || (LocalSync._data[this.root] = []);"," }",""," // Map each model's ID to its reference inside of data, if there"," // are already existing models inside of `localStorage`."," LocalSync._idMap[this.root] || (LocalSync._idMap[this.root] = {});"," Y.Array.each(LocalSync._data[this.root], function (item) {"," var id = item.id;"," if (id) {"," LocalSync._idMap[this.root][id] = item;"," }"," }, this);"," },"," "," // -- Public Methods -----------------------------------------------------------"," "," /**"," Creates a synchronization layer with the localStorage API, if available."," Otherwise, falls back to a in-memory data store.",""," This method is called internally by load(), save(), and destroy().",""," @method sync"," @param {String} action Sync action to perform. May be one of the following:",""," * **create**: Store a newly-created model for the first time."," * **read** : Load an existing model."," * **update**: Update an existing model."," * **delete**: Delete an existing model.",""," @param {Object} [options] Sync options"," @param {callback} [callback] Called when the sync operation finishes."," @param {Error|null} callback.err If an error occurred, this parameter will"," contain the error. If the sync operation succeeded, _err_ will be"," falsey."," @param {Any} [callback.response] The response from our sync. This value will"," be passed to the parse() method, which is expected to parse it and"," return an attribute hash."," **/"," sync: function (action, options, callback) {"," options || (options = {});"," var response, errorInfo;",""," try {"," switch (action) {"," case 'read':"," if (this._isYUIModelList) {"," response = this._index(options);"," } else {"," response = this._show(options);"," }"," break;"," case 'create':"," response = this._create(options);"," break;"," case 'update':"," response = this._update(options);"," break;"," case 'delete':"," response = this._destroy(options);"," break;"," }"," } catch (error) {"," errorInfo = error.message;"," }",""," if (response) {"," callback(null, response);"," } else if (errorInfo) {"," callback(errorInfo);"," } else {"," callback(\"Data not found in LocalStorage\");"," }"," },",""," /**"," Generate a random GUID for our Models. This can be overriden if you have"," another method of generating different IDs."," "," @method generateID"," @protected"," @param {String} pre Optional GUID prefix"," **/"," generateID: function (pre) {"," return Y.guid(pre + '_');"," },",""," // -- Protected Methods ----------------------------------------------------",""," /**"," Sync method correlating to the \"read\" operation, for a Model List"," "," @method _index"," @return {Object[]} Array of objects found for that root key"," @protected"," @since 3.13.0"," **/"," _index: function () {"," return LocalSync._data[this.root];"," },",""," /**"," Sync method correlating to the \"read\" operation, for a Model"," "," @method _show"," @return {Object} Object found for that root key and model ID"," @protected"," @since 3.13.0"," **/"," _show: function () {"," return LocalSync._idMap[this.root][this.get('id')] || null;"," },"," "," /**"," Sync method correlating to the \"create\" operation"," "," @method _show"," @return {Object} The new object created."," @protected"," @since 3.13.0"," **/"," _create: function () {"," var hash = this.toJSON(),"," data = LocalSync._data[this.root],"," idMap = LocalSync._idMap[this.root];"," "," hash.id = this.generateID(this.root);"," data.push(hash);"," idMap[hash.id] = hash;",""," this._save();"," return hash;"," },",""," /**"," Sync method correlating to the \"update\" operation",""," @method _update"," @return {Object} The updated object."," @protected"," @since 3.13.0"," **/"," _update: function () {"," var hash = Y.merge(this.toJSON());"," LocalSync._idMap[this.get('id')] = hash;"," "," this._save();"," return hash;"," },",""," /**"," Sync method correlating to the \"delete\" operation. Deletes the data"," from the in-memory object, and saves into localStorage if available."," "," @method _destroy"," @return {Object} The deleted object."," @protected"," @since 3.13.0"," **/"," _destroy: function () {"," delete LocalSync._idMap[this.get('id')];"," this._save();"," return this.toJSON();"," },"," "," /**"," Saves the current in-memory store into a localStorage key/value pair"," if localStorage is available; otherwise, does nothing."," "," @method _save"," @protected"," @since 3.13.0"," **/"," _save: function () {"," if (LocalSync._hasLocalStorage) {"," this.storage && this.storage.setItem("," this.root,"," Y.JSON.stringify(LocalSync._data[this.root])"," );"," }"," }","};","","// -- Namespace ---------------------------------------------------------------","","Y.namespace('ModelSync').Local = LocalSync;","","","}, '3.13.0', {\"requires\": [\"model\", \"json-stringify\"]});","","}());"]};