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

Side by Side Diff: pkg/polymer/lib/platform.dart

Issue 41293002: Fixes from polymer.dart API review (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Made Job a part of polymer Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698