Commit d21cdad4 authored by Yaxel Perez's avatar Yaxel Perez

.

parent aa84a60b
/*global define, jIO */
/*jslint nomen: true*/
(function (jIO) {
"use strict";
function randomId() {
// https://gist.github.com/gordonbrander/2230317
return '_' + Math.random().toString(36).substr(2, 9);
}
function ListStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
this._signature_storage = jIO.createJIO({
"type": "indexeddb",
"database": randomId()
});
this._signature_storage.post("_", {
list: []
});
}
ListStorage.prototype.post = function () {
console.log('alright alright alright alright alright ok now ladies');
var id = this._sub_storage.post.apply(this._sub_storage, arguments),
updated_list = this._signature_storage.get("_").list.concat(id);
this._signature_storage.put("_", {list: updated_list});
};
ListStorage.prototype.get = function () {
return this._sub_storage.get.apply(this._sub_storage, arguments);
};
ListStorage.prototype.put = function () {
return this._sub_storage.put.apply(this._sub_storage, arguments);
};
ListStorage.prototype.remove = function (id) {
var updated_list = this._signature_storage.get("_")
.list.filter(function (x) { return x !== id; });
this._signature_storage.put("_", { list: updated_list });
};
ListStorage.prototype.list = function () {
return this._sub_storage.get("_").list;
};
jIO.addStorage("list", ListStorage);
}(jIO));
(function (jIO, RSVP, QUnit) {
"use strict";
QUnit.module("ListStorage");
QUnit.test('Constructor does not crash', function () {
jIO.createJIO({
type: "list",
sub_storage: {
type: "memory"
}
});
QUnit.expect(0);
});
// line is too long (>80) if I don't do this weird indenting
QUnit.test(
"Storage list method returns ordered list of ids",
function (assert) {
var storage = jIO.createJIO({
type: "list",
sub_storage: {
type: "uuid",
sub_storage: {
type: "memory",
}
}
}),
ids = RSVP.all([storage.post(), storage.post(), storage.post()]);
ids.then(function (values) {
});
}
);
}(jIO, RSVP, QUnit));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment