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

Side by Side Diff: pkg/polymer/lib/src/instance.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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of polymer; 5 part of polymer;
6 6
7 /** 7 /**
8 * Use this annotation to publish a field as an attribute. For example: 8 * Use this annotation to publish a field as an attribute. For example:
9 * 9 *
10 * class MyPlaybackElement extends PolymerElement { 10 * class MyPlaybackElement extends PolymerElement {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 */ 75 */
76 static Future get onReady => _ready.future; 76 static Future get onReady => _ready.future;
77 77
78 PolymerDeclaration _declaration; 78 PolymerDeclaration _declaration;
79 79
80 /** The most derived `<polymer-element>` declaration for this element. */ 80 /** The most derived `<polymer-element>` declaration for this element. */
81 PolymerDeclaration get declaration => _declaration; 81 PolymerDeclaration get declaration => _declaration;
82 82
83 Map<String, StreamSubscription> _observers; 83 Map<String, StreamSubscription> _observers;
84 bool _unbound; // lazy-initialized 84 bool _unbound; // lazy-initialized
85 Job _unbindAllJob; 85 _Job _unbindAllJob;
86 86
87 StreamSubscription _propertyObserver; 87 StreamSubscription _propertyObserver;
88 88
89 bool get _elementPrepared => _declaration != null; 89 bool get _elementPrepared => _declaration != null;
90 90
91 bool get applyAuthorStyles => false; 91 bool get applyAuthorStyles => false;
92 bool get resetStyleInheritance => false; 92 bool get resetStyleInheritance => false;
93 bool get alwaysPrepare => false; 93 bool get alwaysPrepare => false;
94 bool get preventDispose => false; 94 bool get preventDispose => false;
95 95
(...skipping 18 matching lines...) Expand all
114 * Gets the shadow root associated with the corresponding custom element. 114 * Gets the shadow root associated with the corresponding custom element.
115 * 115 *
116 * This is identical to [shadowRoot], unless there are multiple levels of 116 * This is identical to [shadowRoot], unless there are multiple levels of
117 * inheritance and they each have their own shadow root. For example, 117 * inheritance and they each have their own shadow root. For example,
118 * this can happen if the base class and subclass both have `<template>` tags 118 * this can happen if the base class and subclass both have `<template>` tags
119 * in their `<polymer-element>` tags. 119 * in their `<polymer-element>` tags.
120 */ 120 */
121 // TODO(jmesserly): Polymer does not have this feature. Reconcile. 121 // TODO(jmesserly): Polymer does not have this feature. Reconcile.
122 ShadowRoot getShadowRoot(String customTagName) => _shadowRoots[customTagName]; 122 ShadowRoot getShadowRoot(String customTagName) => _shadowRoots[customTagName];
123 123
124 /**
125 * Invoke [callback] in [wait], unless the job is re-registered,
126 * which resets the timer. For example:
127 *
128 * _myJob = job(_myJob, callback, const Duration(milliseconds: 100));
129 *
130 * Returns a job handle which can be used to re-register a job.
131 */
132 Job job(Job job, void callback(), Duration wait) =>
133 runJob(job, callback, wait);
134
135 void polymerCreated() { 124 void polymerCreated() {
136 if (this.ownerDocument.window != null || alwaysPrepare || 125 if (this.ownerDocument.window != null || alwaysPrepare ||
137 _preparingElements > 0) { 126 _preparingElements > 0) {
138 prepareElement(); 127 prepareElement();
139 } 128 }
140 } 129 }
141 130
142 /** Retrieves the custom element name by inspecting the host node. */ 131 /** Retrieves the custom element name by inspecting the host node. */
143 String get _customTagName { 132 String get _customTagName {
144 var isAttr = attributes['is']; 133 var isAttr = attributes['is'];
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } 437 }
449 } 438 }
450 439
451 Map<String, NodeBinding> get bindings => nodeBindFallback(this).bindings; 440 Map<String, NodeBinding> get bindings => nodeBindFallback(this).bindings;
452 441
453 void unbind(String name) => nodeBindFallback(this).unbind(name); 442 void unbind(String name) => nodeBindFallback(this).unbind(name);
454 443
455 void asyncUnbindAll() { 444 void asyncUnbindAll() {
456 if (_unbound == true) return; 445 if (_unbound == true) return;
457 _unbindLog.fine('[$localName] asyncUnbindAll'); 446 _unbindLog.fine('[$localName] asyncUnbindAll');
458 _unbindAllJob = job(_unbindAllJob, unbindAll, const Duration(seconds: 0)); 447 _unbindAllJob = _runJob(_unbindAllJob, unbindAll, Duration.ZERO);
459 } 448 }
460 449
461 void unbindAll() { 450 void unbindAll() {
462 if (_unbound == true) return; 451 if (_unbound == true) return;
463 452
464 unbindAllProperties(); 453 unbindAllProperties();
465 nodeBindFallback(this).unbindAll(); 454 nodeBindFallback(this).unbindAll();
466 455
467 var root = shadowRoot; 456 var root = shadowRoot;
468 while (root != null) { 457 while (root != null) {
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 * 871 *
883 * If you would prefer to run the callback using 872 * If you would prefer to run the callback using
884 * [window.requestAnimationFrame], see the [async] method. 873 * [window.requestAnimationFrame], see the [async] method.
885 */ 874 */
886 // Dart note: "async" is split into 2 methods so it can have a sensible type 875 // Dart note: "async" is split into 2 methods so it can have a sensible type
887 // signatures. Also removed the various features that don't make sense in a 876 // signatures. Also removed the various features that don't make sense in a
888 // Dart world, like binding to "this" and taking arguments list. 877 // Dart world, like binding to "this" and taking arguments list.
889 Timer asyncTimer(void method(), Duration timeout) { 878 Timer asyncTimer(void method(), Duration timeout) {
890 // when polyfilling Object.observe, ensure changes 879 // when polyfilling Object.observe, ensure changes
891 // propagate before executing the async method 880 // propagate before executing the async method
892 platform.flush(); 881 scheduleMicrotask(Observable.dirtyCheck);
893 return new Timer(timeout, method); 882 return new Timer(timeout, method);
894 } 883 }
895 884
896 /** 885 /**
897 * Invokes a function asynchronously. 886 * Invokes a function asynchronously.
898 * This will call `Platform.flush()` and then call 887 * This will call `Platform.flush()` and then call
899 * [window.requestAnimationFrame] with the provided [method] and return the 888 * [window.requestAnimationFrame] with the provided [method] and return the
900 * result. 889 * result.
901 * 890 *
902 * If you would prefer to run the callback after a given duration, see 891 * If you would prefer to run the callback after a given duration, see
903 * the [asyncTimer] method. 892 * the [asyncTimer] method.
904 */ 893 */
905 int async(RequestAnimationFrameCallback method) { 894 int async(RequestAnimationFrameCallback method) {
906 // when polyfilling Object.observe, ensure changes 895 // when polyfilling Object.observe, ensure changes
907 // propagate before executing the async method 896 // propagate before executing the async method
908 platform.flush(); 897 scheduleMicrotask(Observable.dirtyCheck);
909 return window.requestAnimationFrame(method); 898 return window.requestAnimationFrame(method);
910 } 899 }
911 900
912 /** 901 /**
913 * Fire a [CustomEvent] targeting [toNode], or this if toNode is not 902 * Fire a [CustomEvent] targeting [toNode], or this if toNode is not
914 * supplied. Returns the [detail] object. 903 * supplied. Returns the [detail] object.
915 */ 904 */
916 Object fire(String type, {Object detail, Node toNode, bool canBubble}) { 905 Object fire(String type, {Object detail, Node toNode, bool canBubble}) {
917 var node = toNode != null ? toNode : this; 906 var node = toNode != null ? toNode : this;
918 //log.events && console.log('[%s]: sending [%s]', node.localName, inType); 907 //log.events && console.log('[%s]: sending [%s]', node.localName, inType);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 class PolymerElement extends HtmlElement with Polymer, Observable { 1127 class PolymerElement extends HtmlElement with Polymer, Observable {
1139 PolymerElement.created() : super.created() { 1128 PolymerElement.created() : super.created() {
1140 polymerCreated(); 1129 polymerCreated();
1141 } 1130 }
1142 } 1131 }
1143 1132
1144 class _PropertyValue { 1133 class _PropertyValue {
1145 Object oldValue, newValue; 1134 Object oldValue, newValue;
1146 _PropertyValue(this.oldValue); 1135 _PropertyValue(this.oldValue);
1147 } 1136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698