-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f81013
commit 7a5998c
Showing
15 changed files
with
135 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
part of cargo_client; | ||
|
||
class IndexDbCargo extends Cargo { | ||
String dbName; | ||
String storeName; | ||
|
||
bool _isOpen; | ||
|
||
int count = 0; | ||
|
||
/// Returns true if IndexedDB is supported on this platform. | ||
static bool get supported => IdbFactory.supported; | ||
|
||
static Map<String, Database> _databases = new Map<String, Database>(); | ||
|
||
IndexDbCargo(this.dbName, this.storeName) : super._(); | ||
|
||
dynamic getItemSync(String key) { | ||
throw new UnsupportedError('IndexedDB is not supporting synchronous retrieval of data'); | ||
} | ||
|
||
Future getItem(String key) { | ||
return _doCommand((ObjectStore store) => store.delete(key)); | ||
} | ||
|
||
void setItem(String key, data) { | ||
_doCommand((ObjectStore store) { | ||
return store.put(key, data); | ||
}); | ||
|
||
dispatch(key, data); | ||
} | ||
|
||
void removeItem(String key) { | ||
_doCommand((ObjectStore store) => store.delete(key)); | ||
} | ||
|
||
void clear() { | ||
_doCommand((ObjectStore store) => store.clear()); | ||
} | ||
|
||
int length() { | ||
throw new UnsupportedError('IndexedDB is not supporting length retrieval synchronously'); | ||
} | ||
|
||
Future _doCommand(Future requestCommand(ObjectStore store), | ||
[String txnMode = 'readwrite']) { | ||
var completer = new Completer(); | ||
var trans = _db.transaction(storeName, txnMode); | ||
var store = trans.objectStore(storeName); | ||
var future = requestCommand(store); | ||
return trans.completed.then((_) => future); | ||
} | ||
|
||
Future start() { | ||
if (!supported) { | ||
return new Future.error( | ||
new UnsupportedError('IndexedDB is not supported on this platform')); | ||
} | ||
|
||
return window.indexedDB.open(dbName) | ||
.then((Database db) { | ||
//print("Newly opened db $dbName has version ${db.version} and stores ${db.objectStoreNames}"); | ||
if (!db.objectStoreNames.contains(storeName)) { | ||
db.close(); | ||
//print('Attempting upgrading $storeName from ${db.version}'); | ||
return window.indexedDB.open(dbName, | ||
onUpgradeNeeded: (e) { | ||
//print('Upgrading db $dbName to ${db.version + 1}'); | ||
Database d = e.target.result; | ||
d.createObjectStore(storeName); | ||
} | ||
); | ||
} else { | ||
//print('The store $storeName exists in $dbName'); | ||
return db; | ||
} | ||
}) | ||
.then((db){ | ||
_databases[dbName] = db; | ||
_isOpen = true; | ||
return true; | ||
}); | ||
} | ||
|
||
Database get _db => _databases[dbName]; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
part of cargo_client; | ||
|
||
class MemoryCargo extends MemoryImpl implements Cargo { | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
lib/src/client/storage_backend.dart → lib/src/client/storage_impl.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
part of cargo_server; | ||
|
||
class MemoryCargo extends MemoryImpl implements Cargo { | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters