Chromium Code Reviews| Index: pkg/polymer/lib/platform.dart |
| diff --git a/pkg/polymer/lib/platform.dart b/pkg/polymer/lib/platform.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5dc5c3e72241ee5b8d6e38242c678e32c350b495 |
| --- /dev/null |
| +++ b/pkg/polymer/lib/platform.dart |
| @@ -0,0 +1,41 @@ |
| +// Copyright (c) 2013, 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. |
| + |
| +/** |
| + * Exposes helper functionality for interacting with the platform. Similar to |
| + * the [Platform] class from dart:html. |
| + */ |
| +// TODO(jmesserly): in Polymer this is a static class called "Platform", but |
| +// that conflicts with dart:html. What should we do? Does this functionality |
| +// belong in html's Platform instead? |
| +library polymer.platform; |
| + |
| +import 'dart:html' show Text, MutationObserver; |
| +import 'dart:collection' show Queue; |
| +import 'package:observe/src/microtask.dart' show performMicrotaskCheckpoint; |
| + |
| +void flush() { |
| + endOfMicrotask(performMicrotaskCheckpoint); |
| +} |
| + |
| +int _iterations = 0; |
| +final Queue _callbacks = new Queue(); |
| +final Text _twiddle = () { |
| + var twiddle = new Text(''); |
| + new MutationObserver((x, y) { |
|
blois
2013/09/27 21:40:52
TODO that this should convert over to dart:async's
|
| + while (_callbacks.isNotEmpty) { |
| + try { |
| + _callbacks.removeFirst()(); |
| + } catch (e) { // Dart note: fire the error async. |
| + new Completer().completeError(e); |
| + } |
| + } |
| + }).observe(twiddle, characterData: true); |
| + return twiddle; |
| +}(); |
| + |
| +void endOfMicrotask(void callback()) { |
| + _twiddle.text = '${_iterations++}'; |
| + _callbacks.add(callback); |
| +} |