diff --git a/lib/cargo_client.dart b/lib/cargo_client.dart index a072779..9537ec9 100644 --- a/lib/cargo_client.dart +++ b/lib/cargo_client.dart @@ -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'; diff --git a/lib/src/client/cargo.dart b/lib/src/client/cargo.dart index be2e76c..3ccc269 100644 --- a/lib/src/client/cargo.dart +++ b/lib/src/client/cargo.dart @@ -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}"); } diff --git a/lib/src/client/cargo_mode.dart b/lib/src/client/cargo_mode.dart index 2701371..5331a9f 100644 --- a/lib/src/client/cargo_mode.dart +++ b/lib/src/client/cargo_mode.dart @@ -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'); } \ No newline at end of file diff --git a/lib/src/client/localstorage_backend.dart b/lib/src/client/storage_backend.dart similarity index 91% rename from lib/src/client/localstorage_backend.dart rename to lib/src/client/storage_backend.dart index 98d1d56..0423557 100644 --- a/lib/src/client/localstorage_backend.dart +++ b/lib/src/client/storage_backend.dart @@ -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(); } diff --git a/test/client/memory_test.dart b/test/client/memory_test.dart new file mode 100644 index 0000000..db75c2c --- /dev/null +++ b/test/client/memory_test.dart @@ -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); + }); + }); +} +