|
3 __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,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0,0,0],"14":[0,0],"15":[0,0],"16":[0,0],"17":[0,0],"18":[0,0],"19":[0,0],"20":[0,0],"21":[0,0],"22":[0,0],"23":[0,0],"24":[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,"14":0,"15":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":143,"loc":{"start":{"line":143,"column":54},"end":{"line":143,"column":68}}},"6":{"name":"(anonymous_6)","line":176,"loc":{"start":{"line":176,"column":10},"end":{"line":176,"column":47}}},"7":{"name":"(anonymous_7)","line":220,"loc":{"start":{"line":220,"column":16},"end":{"line":220,"column":31}}},"8":{"name":"(anonymous_8)","line":234,"loc":{"start":{"line":234,"column":12},"end":{"line":234,"column":24}}},"9":{"name":"(anonymous_9)","line":236,"loc":{"start":{"line":236,"column":39},"end":{"line":236,"column":53}}},"10":{"name":"(anonymous_10)","line":251,"loc":{"start":{"line":251,"column":11},"end":{"line":251,"column":23}}},"11":{"name":"(anonymous_11)","line":263,"loc":{"start":{"line":263,"column":13},"end":{"line":263,"column":25}}},"12":{"name":"(anonymous_12)","line":287,"loc":{"start":{"line":287,"column":13},"end":{"line":287,"column":25}}},"13":{"name":"(anonymous_13)","line":314,"loc":{"start":{"line":314,"column":14},"end":{"line":314,"column":26}}},"14":{"name":"(anonymous_14)","line":328,"loc":{"start":{"line":328,"column":82},"end":{"line":328,"column":98}}},"15":{"name":"(anonymous_15)","line":344,"loc":{"start":{"line":344,"column":11},"end":{"line":344,"column":23}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":359,"column":59}},"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":79,"column":40}},"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":42}},"12":{"start":{"line":91,"column":0},"end":{"line":352,"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":141,"column":65}},"24":{"start":{"line":143,"column":12},"end":{"line":145,"column":21}},"25":{"start":{"line":144,"column":16},"end":{"line":144,"column":77}},"26":{"start":{"line":147,"column":12},"end":{"line":147,"column":78}},"27":{"start":{"line":177,"column":8},"end":{"line":177,"column":34}},"28":{"start":{"line":178,"column":8},"end":{"line":178,"column":32}},"29":{"start":{"line":180,"column":8},"end":{"line":201,"column":9}},"30":{"start":{"line":181,"column":12},"end":{"line":198,"column":13}},"31":{"start":{"line":183,"column":20},"end":{"line":187,"column":21}},"32":{"start":{"line":184,"column":24},"end":{"line":184,"column":56}},"33":{"start":{"line":186,"column":24},"end":{"line":186,"column":55}},"34":{"start":{"line":188,"column":20},"end":{"line":188,"column":26}},"35":{"start":{"line":190,"column":20},"end":{"line":190,"column":53}},"36":{"start":{"line":191,"column":20},"end":{"line":191,"column":26}},"37":{"start":{"line":193,"column":20},"end":{"line":193,"column":53}},"38":{"start":{"line":194,"column":20},"end":{"line":194,"column":26}},"39":{"start":{"line":196,"column":20},"end":{"line":196,"column":54}},"40":{"start":{"line":197,"column":20},"end":{"line":197,"column":26}},"41":{"start":{"line":200,"column":12},"end":{"line":200,"column":38}},"42":{"start":{"line":203,"column":8},"end":{"line":209,"column":9}},"43":{"start":{"line":204,"column":12},"end":{"line":204,"column":37}},"44":{"start":{"line":205,"column":15},"end":{"line":209,"column":9}},"45":{"start":{"line":206,"column":12},"end":{"line":206,"column":32}},"46":{"start":{"line":208,"column":12},"end":{"line":208,"column":55}},"47":{"start":{"line":221,"column":8},"end":{"line":221,"column":33}},"48":{"start":{"line":235,"column":8},"end":{"line":238,"column":15}},"49":{"start":{"line":237,"column":16},"end":{"line":237,"column":43}},"50":{"start":{"line":240,"column":8},"end":{"line":240,"column":20}},"51":{"start":{"line":252,"column":8},"end":{"line":252,"column":55}},"52":{"start":{"line":264,"column":8},"end":{"line":264,"column":34}},"53":{"start":{"line":266,"column":8},"end":{"line":266,"column":45}},"54":{"start":{"line":268,"column":8},"end":{"line":268,"column":40}},"55":{"start":{"line":269,"column":8},"end":{"line":271,"column":9}},"56":{"start":{"line":270,"column":12},"end":{"line":270,"column":48}},"57":{"start":{"line":273,"column":8},"end":{"line":273,"column":50}},"58":{"start":{"line":275,"column":8},"end":{"line":275,"column":21}},"59":{"start":{"line":276,"column":8},"end":{"line":276,"column":20}},"60":{"start":{"line":288,"column":8},"end":{"line":289,"column":32}},"61":{"start":{"line":291,"column":8},"end":{"line":291,"column":35}},"62":{"start":{"line":293,"column":8},"end":{"line":295,"column":9}},"63":{"start":{"line":294,"column":12},"end":{"line":294,"column":43}},"64":{"start":{"line":297,"column":8},"end":{"line":299,"column":9}},"65":{"start":{"line":298,"column":12},"end":{"line":298,"column":49}},"66":{"start":{"line":301,"column":8},"end":{"line":301,"column":21}},"67":{"start":{"line":303,"column":8},"end":{"line":303,"column":20}},"68":{"start":{"line":315,"column":8},"end":{"line":316,"column":35}},"69":{"start":{"line":318,"column":8},"end":{"line":320,"column":9}},"70":{"start":{"line":319,"column":12},"end":{"line":319,"column":19}},"71":{"start":{"line":322,"column":8},"end":{"line":322,"column":35}},"72":{"start":{"line":324,"column":8},"end":{"line":326,"column":9}},"73":{"start":{"line":325,"column":12},"end":{"line":325,"column":35}},"74":{"start":{"line":328,"column":8},"end":{"line":330,"column":11}},"75":{"start":{"line":329,"column":12},"end":{"line":329,"column":33}},"76":{"start":{"line":332,"column":8},"end":{"line":332,"column":21}},"77":{"start":{"line":333,"column":8},"end":{"line":333,"column":29}},"78":{"start":{"line":345,"column":8},"end":{"line":350,"column":9}},"79":{"start":{"line":346,"column":12},"end":{"line":349,"column":14}},"80":{"start":{"line":356,"column":0},"end":{"line":356,"column":43}}},"branchMap":{"1":{"line":79,"type":"binary-expr","locations":[{"start":{"line":79,"column":18},"end":{"line":79,"column":33}},{"start":{"line":79,"column":37},"end":{"line":79,"column":39}}]},"2":{"line":89,"type":"binary-expr","locations":[{"start":{"line":89,"column":19},"end":{"line":89,"column":35}},{"start":{"line":89,"column":39},"end":{"line":89,"column":41}}]},"3":{"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}}]},"4":{"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}}]},"5":{"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}}]},"6":{"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}}]},"7":{"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}}]},"8":{"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}}]},"9":{"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}}]},"10":{"line":141,"type":"binary-expr","locations":[{"start":{"line":141,"column":42},"end":{"line":141,"column":58}},{"start":{"line":141,"column":62},"end":{"line":141,"column":64}}]},"11":{"line":147,"type":"binary-expr","locations":[{"start":{"line":147,"column":12},"end":{"line":147,"column":39}},{"start":{"line":147,"column":44},"end":{"line":147,"column":76}}]},"12":{"line":177,"type":"binary-expr","locations":[{"start":{"line":177,"column":8},"end":{"line":177,"column":15}},{"start":{"line":177,"column":20},"end":{"line":177,"column":32}}]},"13":{"line":181,"type":"switch","locations":[{"start":{"line":182,"column":16},"end":{"line":188,"column":26}},{"start":{"line":189,"column":16},"end":{"line":191,"column":26}},{"start":{"line":192,"column":16},"end":{"line":194,"column":26}},{"start":{"line":195,"column":16},"end":{"line":197,"column":26}}]},"14":{"line":183,"type":"if","locations":[{"start":{"line":183,"column":20},"end":{"line":183,"column":20}},{"start":{"line":183,"column":20},"end":{"line":183,"column":20}}]},"15":{"line":203,"type":"if","locations":[{"start":{"line":203,"column":8},"end":{"line":203,"column":8}},{"start":{"line":203,"column":8},"end":{"line":203,"column":8}}]},"16":{"line":205,"type":"if","locations":[{"start":{"line":205,"column":15},"end":{"line":205,"column":15}},{"start":{"line":205,"column":15},"end":{"line":205,"column":15}}]},"17":{"line":252,"type":"binary-expr","locations":[{"start":{"line":252,"column":15},"end":{"line":252,"column":46}},{"start":{"line":252,"column":50},"end":{"line":252,"column":54}}]},"18":{"line":269,"type":"if","locations":[{"start":{"line":269,"column":8},"end":{"line":269,"column":8}},{"start":{"line":269,"column":8},"end":{"line":269,"column":8}}]},"19":{"line":293,"type":"if","locations":[{"start":{"line":293,"column":8},"end":{"line":293,"column":8}},{"start":{"line":293,"column":8},"end":{"line":293,"column":8}}]},"20":{"line":297,"type":"if","locations":[{"start":{"line":297,"column":8},"end":{"line":297,"column":8}},{"start":{"line":297,"column":8},"end":{"line":297,"column":8}}]},"21":{"line":318,"type":"if","locations":[{"start":{"line":318,"column":8},"end":{"line":318,"column":8}},{"start":{"line":318,"column":8},"end":{"line":318,"column":8}}]},"22":{"line":324,"type":"if","locations":[{"start":{"line":324,"column":8},"end":{"line":324,"column":8}},{"start":{"line":324,"column":8},"end":{"line":324,"column":8}}]},"23":{"line":345,"type":"if","locations":[{"start":{"line":345,"column":8},"end":{"line":345,"column":8}},{"start":{"line":345,"column":8},"end":{"line":345,"column":8}}]},"24":{"line":345,"type":"binary-expr","locations":[{"start":{"line":345,"column":12},"end":{"line":345,"column":38}},{"start":{"line":345,"column":42},"end":{"line":345,"column":54}}]}},"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 = LocalSync._data || {};","","/**","Cache to quickly access a specific object with a given ID.","","@property _store","@type Array","@private","**/","","LocalSync._store = LocalSync._store || {};","","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) {"," LocalSync._store[this.root] = store.split('|') || [];",""," Y.Array.each(LocalSync._store[this.root], function (id) {"," LocalSync._data[id] = Y.JSON.parse(this.storage.getItem(id));"," }, this);"," } else {"," LocalSync._store[this.root] || (LocalSync._store[this.root] = []);"," }"," },"," "," // -- 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 {Function} [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 () {"," var store = LocalSync._store[this.root],"," data = Y.Array.map(store, function (id) {"," return LocalSync._data[id];"," });",""," return data;"," },",""," /**"," 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._data[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();",""," hash.id = this.generateID(this.root);",""," LocalSync._data[hash.id] = hash;"," if (this.storage) {"," this.storage.setItem(hash.id, hash);"," }",""," LocalSync._store[this.root].push(hash.id);",""," 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 = this.toJSON(),"," id = this.get('id');",""," LocalSync._data[id] = hash;"," "," if (this.storage) {"," this.storage.setItem(id, hash);"," }",""," if (Y.Array.indexOf(LocalSync._store[this.root], id) === -1) {"," LocalSync._store[this.root].push(id);"," }",""," 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"," @protected"," @since 3.13.0"," **/"," _destroy: function () {"," var id = this.get('id'),"," storage = this.storage;",""," if (!LocalSync._data[id]) {"," return;"," }",""," delete LocalSync._data[id];",""," if (storage) {"," storage.removeItem(id);"," }",""," LocalSync._store[this.root] = Y.Array.filter(LocalSync._store[this.root], function (item) {"," return item.id != 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,"," LocalSync._store[this.root].join('|')"," );"," }"," }","};","","// -- Namespace ---------------------------------------------------------------","","Y.namespace('ModelSync').Local = LocalSync;","","","}, '@VERSION@', {\"requires\": [\"model\", \"json-stringify\"]});","","}());"]}; |