Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * Exposes helper functionality for interacting with the platform. Similar to | |
| 7 * the [Platform] class from dart:html. | |
| 8 */ | |
| 9 // TODO(jmesserly): in Polymer this is a static class called "Platform", but | |
| 10 // that conflicts with dart:html. What should we do? Does this functionality | |
| 11 // belong in html's Platform instead? | |
| 12 library polymer.platform; | |
| 13 | |
| 14 import 'dart:html' show Text, MutationObserver; | |
| 15 import 'dart:collection' show Queue; | |
| 16 import 'package:observe/src/microtask.dart' show performMicrotaskCheckpoint; | |
| 17 | |
| 18 void flush() { | |
| 19 endOfMicrotask(performMicrotaskCheckpoint); | |
| 20 } | |
| 21 | |
| 22 int _iterations = 0; | |
| 23 final Queue _callbacks = new Queue(); | |
| 24 final Text _twiddle = () { | |
| 25 var twiddle = new Text(''); | |
| 26 new MutationObserver((x, y) { | |
|
blois
2013/09/27 21:40:52
TODO that this should convert over to dart:async's
| |
| 27 while (_callbacks.isNotEmpty) { | |
| 28 try { | |
| 29 _callbacks.removeFirst()(); | |
| 30 } catch (e) { // Dart note: fire the error async. | |
| 31 new Completer().completeError(e); | |
| 32 } | |
| 33 } | |
| 34 }).observe(twiddle, characterData: true); | |
| 35 return twiddle; | |
| 36 }(); | |
| 37 | |
| 38 void endOfMicrotask(void callback()) { | |
| 39 _twiddle.text = '${_iterations++}'; | |
| 40 _callbacks.add(callback); | |
| 41 } | |
| OLD | NEW |