Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1763)

Unified Diff: tools/dom/templates/html/impl/impl_IDBObjectStore.darttemplate

Issue 12159005: Dartifying some IndexedDB APIs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/dom/templates/html/impl/impl_IDBObjectStore.darttemplate
diff --git a/tools/dom/templates/html/impl/impl_IDBObjectStore.darttemplate b/tools/dom/templates/html/impl/impl_IDBObjectStore.darttemplate
new file mode 100644
index 0000000000000000000000000000000000000000..1dbc02122eccbefc8bcf4125cc6f010ad880abee
--- /dev/null
+++ b/tools/dom/templates/html/impl/impl_IDBObjectStore.darttemplate
@@ -0,0 +1,95 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of $LIBRARYNAME;
+
+$(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
+
+ @DomName('IDBObjectStore.put')
+ Future<Object> put(value, [key]) {
+ try {
+ var request;
+ if (key != null) {
+ request = $dom_put(value, key);
+ } else {
+ request = $dom_put(value);
+ }
+ return _completeRequest(request, new Completer<Object>());
+ } catch (e) {
+ return new Future.immediateError(e);
+ }
+ }
+
+ @DomName('IDBObjectStore.getObject')
+ Future<Object> getObject(key) {
+ try {
+ var request = $dom_getObject(key);
+
+ return _completeRequest(request, new Completer<Object>());
+ } catch (e) {
+ return new Future.immediateError(e);
+ }
+ }
+
+ /**
+ * Creates a stream of cursors over the records in this object store.
+ *
+ * The stream must be manually advanced by calling [Cursor.next] after
+ * each item or by specifying autoAdvance to be true.
+ *
+ * Asynchronous operations which are not related to the current transaction
+ * will cause the transaction to automatically be committed- all processing
+ * must be done synchronously unless they are additional async requests to
+ * the current transaction.
+ */
+ @DomName('IDBObjectStore.openCursor')
+ Stream<Cursor> openCursor({key, KeyRange range, String direction,
+ bool autoAdvance}) {
+ var key_OR_range = null;
+ if (key != null) {
+ if (range != null) {
+ throw new ArgumentError('Cannot specify both key and range.');
+ }
+ key_OR_range = key;
+ } else {
+ key_OR_range = range;
+ }
+
+ // TODO: try/catch this and return a stream with an immediate error.
+ var request;
+ if (direction == null) {
+ request = $dom_openCursor(key_OR_range);
+ } else {
+ request = $dom_openCursor(key_OR_range, direction);
+ }
+ return _cursorStreamFromResult(request, autoAdvance);
+ }
+
+$!MEMBERS
+
+ /**
+ * Helper for iterating over cursors in a request.
+ */
+ static Stream<Cursor> _cursorStreamFromResult(Request request,
+ bool autoAdvance) {
+ var controller = new StreamController<Cursor>();
+
+ request.onError.listen((e) {
+ controller.signalError(e);
+ });
+
+ request.onSuccess.listen((e) {
+ Cursor cursor = request.result;
+ if (cursor == null) {
+ controller.close();
+ } else {
+ controller.add(cursor);
+ if (autoAdvance == true) {
+ cursor.next();
+ }
+ }
+ });
+ return controller.stream;
+ }
+}
« tests/html/utils.dart ('K') | « tools/dom/templates/html/impl/impl_IDBFactory.darttemplate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698