Mercurial > browser-couch
changeset 29:7fe72409d8f1
Added a FakeStorage backend and made the big test use it.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 13 Apr 2009 16:25:24 -0700 |
parents | 6b79ea22097e |
children | e136ddfc6175 |
files | big.js browser-couch.js |
diffstat | 2 files changed, 51 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/big.js Mon Apr 13 16:08:52 2009 -0700 +++ b/big.js Mon Apr 13 16:25:24 2009 -0700 @@ -108,7 +108,9 @@ }} ); } - }); + }, + new FakeStorage() + ); } window.addEventListener("load", start, false);
--- a/browser-couch.js Mon Apr 13 16:08:52 2009 -0700 +++ b/browser-couch.js Mon Apr 13 16:25:24 2009 -0700 @@ -84,6 +84,46 @@ } }; +function FakeStorage() { + var db = {}; + + function deepCopy(obj) { + if (typeof(obj) == "object") { + var copy; + + if (obj.constructor.name == "Array") + copy = new Array(); + else + copy = new Object(); + + for (name in obj) { + if (obj.hasOwnProperty(name)) { + var property = obj[name]; + if (typeof(property) == "object") + copy[name] = deepCopy(property); + else + copy[name] = property; + } + } + + return copy; + } else + return obj; + } + + this.get = function FS_get(name, cb) { + if (!(name in db)) + cb(null); + else + cb(db[name]); + }; + + this.put = function FS_put(name, obj, cb) { + db[name] = deepCopy(obj); + cb(); + }; +}; + function LocalStorage(JSON) { var storage; @@ -191,14 +231,6 @@ var self = this; var dbName = 'BrowserCouch_DB_' + name; - storage.get( - dbName, - function(obj) { - if (obj) - dict.unpickle(obj); - cb(self); - }); - function commitToStorage(cb) { if (!cb) cb = function() {}; @@ -246,6 +278,14 @@ options.finished, options.chunkSize); }; + + storage.get( + dbName, + function(obj) { + if (obj) + dict.unpickle(obj); + cb(self); + }); }, _mapReduce: function BC__mapReduce(map, reduce, dict, progress,