the Memory Object Cache System of the mass framework, which adds a uniqueid to the proxy object corresponding to the target object or target object to link the corresponding cache body. Store data to the corresponding cache body Through Dom. Data.
// ================================================ ==============/// Data cache module ================================== ============================ (function (global, doc) {var dom = global [Doc. URL. replace (/(#. + | \ W)/g, '')]; Dom. define ("data", "Lang", function () {Dom. log ("loaded data module"); var remitter =/object | function/Dom. mix (DOM, {memcache :{},/** @ Param {Any} target * @ Param {string | object} name * @ Param {Any} data **/data: functio N (target, name, Data, PVT) {If (target & remitter. test (typeof target) {var id = target. uniquenumber | (target. uniquenumber = ++ Dom ["@ UUID"]); If (name = "@ UUID") {return ID;} var memcache = target. nodetype = 1? Dom. memcache: Target; var table = memcache ["@ data _" + id] | (memcache ["@ data _" + id] ={}); If (! Pvt) {table = table. data | (table. data ={}) ;}var getbyname = typeof name = "string"; if (Name & typeof name = "object") {Dom. mix (table, name);} else if (getbyname & Data! = Void 0) {table [name] = data;} return getbyname? Table [name]: Table; }}, _ DATA: function (target, name, data) {return Dom. data (target, name, Data, true)},/** @ Param {Any} target * @ Param {string | opt} Name **/removedata: function (target, name, PVT) {If (target & remitter. test (typeof target) {var id = target. uniquenumber; If (! ID) {return;} var memcache = target. nodetype = 1? Dom. memcache: Target; var table = memcache ["@ data _" + id], clear = 1, ret = typeof name = "string"; if (Table & RET) {If (! Pvt) {table = table. data} If (table) {ret = table [name]; Delete table [name];} var cache = memcache ["@ data _" + id]; loop: for (var key in cache) {If (Key = "data") {for (var I in cache. data) {clear = 0; break loop;} else {clear = 0; break loop;} If (clear) {Delete memcache ["@ data _" + id];} return ret ;}}, /** merge the data cache body of the object DEST to the data cache body of SRC * @ Param {Any} target * @ Param {string | opt} Name **/mergedata: function (clone, Src) {var srcdata = Dom. _ data (SRC), clonedata = Dom. _ data (clone); If (srcdata & clonedata) {Dom. object. merge. call (clonedata, srcdata) ;}}}); Modify temporary parameter values (this,this.doc ument); // change uniqueid to uniquenumber to simplify data and removedata // Add Dom to 2011.9.28. _ data processing internal data
Example
Dom. require ("data", function () {var A ={}; // write data with Dom. data (a, "name", "situ zhengmei"); // read the data Dom. log (a); // {uniquenumber: 2, "@ data_2": {data: {name: "situ zhengmei" }}var B ={}; Dom. data (B, "sex", "man"); // merge the data Dom. mergedata (B, A); Dom. log (B); // {uniquenumber: 3, "@ data_3": {data: {name: "situ zhengmei", sex: "Man" }}// Delete the data Dom. removedata (B, "name"); Dom. log (B); // {uniquenumber: 3, "@ data_3": {data: {sex: "Man" }}} Dom. data (B, "inner", "innerhtml", true); Dom. log (B); // {uniquenumber: 3, "@ data_3": {inner: "innerhtml", data: {sex: "Man "}}}});