| 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:async' show Completer; | |
| 15 import 'dart:html' show Text, MutationObserver; | |
| 16 import 'dart:collection' show Queue; | |
| 17 import 'package:observe/observe.dart'; | |
| 18 | |
| 19 void flush() => endOfMicrotask(Observable.dirtyCheck); | |
| 20 | |
| 21 int _iterations = 0; | |
| 22 final Queue _callbacks = new Queue(); | |
| 23 final Text _twiddle = () { | |
| 24 var twiddle = new Text(''); | |
| 25 new MutationObserver((x, y) { | |
| 26 while (_callbacks.isNotEmpty) { | |
| 27 try { | |
| 28 _callbacks.removeFirst()(); | |
| 29 } catch (e) { // Dart note: fire the error async. | |
| 30 new Completer().completeError(e); | |
| 31 } | |
| 32 } | |
| 33 }).observe(twiddle, characterData: true); | |
| 34 return twiddle; | |
| 35 }(); | |
| 36 | |
| 37 void endOfMicrotask(void callback()) { | |
| 38 _twiddle.text = '${_iterations++}'; | |
| 39 _callbacks.add(callback); | |
| 40 } | |
| OLD | NEW |