Skip to content

Commit

Permalink
adding sessionstorage for free and some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jorishermans committed Jul 4, 2014
1 parent 7ae80df commit b651c1d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/cargo_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:async';
import 'package:cargo/cargo_base.dart';

part 'src/client/cargo.dart';
part 'src/client/localstorage_backend.dart';
part 'src/client/storage_backend.dart';
part 'src/client/memory_client.dart';
part 'src/client/cargo_mode.dart';

4 changes: 3 additions & 1 deletion lib/src/client/cargo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ abstract class Cargo extends CargoBase {
case CargoMode.MEMORY:
return new MemoryClient();
case CargoMode.LOCAL:
return new LocalstorageBackend();
return new LocalstorageBackend(window.localStorage);
case CargoMode.SESSION:
return new LocalstorageBackend(window.sessionStorage);
default:
Logger.root.warning("Error: Unsupported storage backend \"${MODE}\", supported backends on server is: ${CargoMode.MEMORY} and ${CargoMode.LOCAL}");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/client/cargo_mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ class CargoMode {
/// all the cargo modes for the client implementations
static const MEMORY = const CargoModeHolder('Memory');
static const LOCAL = const CargoModeHolder('Local');

static const SESSION = const CargoModeHolder('Session');
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ part of cargo_client;

class LocalstorageBackend implements Cargo {
Completer _completer;
Storage values = window.localStorage;

LocalstorageBackend() {
Storage values;
LocalstorageBackend(this.values) {
_completer = new Completer();
_completer.complete();
}
Expand Down
18 changes: 18 additions & 0 deletions test/client/memory_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:unittest/unittest.dart';
import 'package:cargo/cargo_client.dart';

void main() {
// First tests!
Cargo storage = new Cargo(MODE: CargoMode.MEMORY);

storage.start().then((_) {
test('test basic memory storage', () {
storage.setItem("data", {"data": "data"});

var data = storage.getItemSync("data");
expect(data["data"], "data");
expect(storage.length(), 1);
});
});
}

0 comments on commit b651c1d

Please sign in to comment.