Skip to content

Commit

Permalink
add exportSync and export method to the game
Browse files Browse the repository at this point in the history
  • Loading branch information
jorishermans committed Oct 16, 2014
1 parent 47bbeeb commit 8c0d25e
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This file contains highlights of what changes on each version of the cargo package.

#### Pub version 0.4.2 ####

- export & exportSync methods

#### Pub version 0.4.1+1 ####

- Change of directory for temporary data for testing
Expand Down
6 changes: 4 additions & 2 deletions lib/src/cargo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ abstract class CargoBase {
return getItemSync(key);
}

Map export();
Map exportSync();

Future<Map> export();

CargoBase copyTo(CargoBase storage) {
this.export().forEach((key, value) => storage.add(key, value));
this.exportSync().forEach((key, value) => storage.add(key, value));
return storage;
}

Expand Down
15 changes: 14 additions & 1 deletion lib/src/client/indexdb_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,26 @@ class IndexDbCargo extends Cargo {
});
}

Map export() {
Map exportSync() {
Map values = new Map();
for (var key in keys) {
values[key] = getItemSync(key);
}
return values;
}

Future<Map> export() {
Completer complete = new Completer();
Map values = new Map();
_doCommand((ObjectStore store) {
store.openCursor().listen((CursorWithValue cwv) {
values[cwv.key] = cwv.value;
}).onDone(() {
complete.complete(values);
});;
});
return complete.future;
}

Database get _db => _databases[dbName];
}
8 changes: 7 additions & 1 deletion lib/src/client/storage_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ class LocalstorageCargo extends Cargo {
return values.length;
}

Map export() {
Map exportSync() {
return values;
}

Future<Map> export() {
Completer complete = new Completer();
complete.complete(values);
return complete.future;
}

Future start() => _completer.future;
}
24 changes: 23 additions & 1 deletion lib/src/server/file_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,35 @@ class FileCargo extends Cargo {
});
}

Map export() {
Map exportSync() {
Map values = new Map();
for (var key in keys) {
values[key] = getItemSync(key);
}
return values;
}

Future<Map> export() {
Completer complete = new Completer();

Map values = new Map();

Directory dir = new Directory(pathToStore);
dir.list(recursive: true, followLinks: false).listen((FileSystemEntity entity) {
var path = entity.path;

if (path.indexOf(".json") > 1) {
var fileName = path.split('\\').last;
fileName = fileName.replaceAll(".json", '');
var key = fileName.toString();

values[key] = getItemSync(key);
}
}).onDone(() {
complete.complete(values);
});
return complete.future;
}

void clear() {
Directory dir = new Directory(pathToStore);
Expand Down
8 changes: 7 additions & 1 deletion lib/src/shared/memory_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ class MemoryImpl extends CargoBase with CargoDispatch {
return values.length;
}

Map export() {
Map exportSync() {
return values;
}

Future<Map> export() {
Completer complete = new Completer();
complete.complete(values);
return complete.future;
}

Future start() => _completer.future;
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: cargo
version: 0.4.1+1
version: 0.4.2
author: Joris Hermans <hermansj@gmail.com>
description: A key value, storage library for dart
homepage: https://github.com/ForceUniverse/cargo
Expand Down

0 comments on commit 8c0d25e

Please sign in to comment.