Ox.localStorage: fix chaining, add tests

This commit is contained in:
rolux 2012-06-15 09:43:55 +02:00
parent d2322388dc
commit 37ee99f884

View file

@ -142,6 +142,13 @@ Ox.localStorage <f> localStorage wrapper
(key) -> <*> returns one value (key) -> <*> returns one value
(key, val) -> <f> sets one value, returns localStorage object (key, val) -> <f> sets one value, returns localStorage object
({key: val, ...}) -> <f> sets values, returns localStorage object ({key: val, ...}) -> <f> sets values, returns localStorage object
<script>
Ox.test.localStorage = Ox.localStorage('test');
</script>
> Ox.test.localStorage({foo: 'bar'})('foo')
'bar'
> Ox.test.localStorage.delete('foo')()
{}
@*/ @*/
Ox.localStorage = function(namespace) { Ox.localStorage = function(namespace) {
if (!window.localStorage) { if (!window.localStorage) {
@ -164,7 +171,7 @@ Ox.localStorage = function(namespace) {
Ox.forEach(Ox.makeObject(arguments), function(value, key) { Ox.forEach(Ox.makeObject(arguments), function(value, key) {
localStorage[namespace + '.' + key] = JSON.stringify(value); localStorage[namespace + '.' + key] = JSON.stringify(value);
}); });
ret = this; ret = storage;
} }
return ret; return ret;
}; };
@ -175,8 +182,6 @@ Ox.localStorage = function(namespace) {
keys.forEach(function(key) { keys.forEach(function(key) {
delete localStorage[namespace + '.' + key]; delete localStorage[namespace + '.' + key];
}); });
var keys =
keys
return storage; return storage;
}; };
return storage; return storage;
@ -257,7 +262,7 @@ Ox.loop <f> For-loop, functional-style
step <n> Step value step <n> Step value
fn <f> Iterator function fn <f> Iterator function
i <n> Counter value i <n> Counter value
> Ox.loop(10, function(i) { i == 4 && Ox.Break() }) > Ox.loop(10, function(i) { i == 4 && Ox.Break(); })
4 4
> Ox.loop(0, 3, 2, function() {}) > Ox.loop(0, 3, 2, function() {})
4 4
@ -295,8 +300,7 @@ Ox.print <f> Prints its arguments to the console
"foo" "foo"
@*/ @*/
Ox.print = function() { Ox.print = function() {
var args = Ox.toArray(arguments), var args = Ox.toArray(arguments), date = new Date();
date = new Date();
args.unshift( args.unshift(
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().slice(-3) Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().slice(-3)
); );