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

Unified Diff: third_party/pkg/angular/lib/core_dom/ng_element.dart

Issue 257423008: Update all Angular libs (run update_all.sh). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/lib/core_dom/ng_element.dart
diff --git a/third_party/pkg/angular/lib/core_dom/ng_element.dart b/third_party/pkg/angular/lib/core_dom/ng_element.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b6d12d022f0f87903e9d4e4b6e0fa2d3b16da43e
--- /dev/null
+++ b/third_party/pkg/angular/lib/core_dom/ng_element.dart
@@ -0,0 +1,67 @@
+part of angular.core.dom_internal;
+
+@Injectable()
+class NgElement {
+ static const _TO_BE_REMOVED = const Object();
+
+ final dom.Element node;
+ final Scope _scope;
+ final Animate _animate;
+
+ final _classesToUpdate = <String, bool>{};
+ final _attributesToUpdate = <String, dynamic>{};
+
+ bool _writeScheduled = false;
+
+ NgElement(this.node, this._scope, this._animate);
+
+ void addClass(String className) {
+ _scheduleDomWrite();
+ _classesToUpdate[className] = true;
+ }
+
+ void removeClass(String className) {
+ _scheduleDomWrite();
+ _classesToUpdate[className] = false;
+ }
+
+ void setAttribute(String attrName, [value = '']) {
+ _scheduleDomWrite();
+ _attributesToUpdate[attrName] = value == null ? '' : value;
+ }
+
+ void removeAttribute(String attrName) {
+ _scheduleDomWrite();
+ _attributesToUpdate[attrName] = _TO_BE_REMOVED;
+ }
+
+ /// Schedules a DOM write for the next flush phase
+ _scheduleDomWrite() {
+ if (!_writeScheduled) {
+ _writeScheduled = true;
+ _scope.rootScope.domWrite(() {
+ _writeToDom();
+ _writeScheduled = false;
+ });
+ }
+ }
+
+ /// Executes scheduled DOM update - this should be called from the flush phase
+ _writeToDom() {
+ _classesToUpdate.forEach((String className, bool toBeAdded) {
+ toBeAdded
+ ? _animate.addClass(node, className)
+ : _animate.removeClass(node, className);
+ });
+ _classesToUpdate.clear();
+
+ _attributesToUpdate.forEach((String attrName, value) {
+ if (value == _TO_BE_REMOVED) {
+ node.attributes.remove(attrName);
+ } else {
+ node.attributes[attrName] = value;
+ }
+ });
+ _attributesToUpdate.clear();
+ }
+}
« no previous file with comments | « third_party/pkg/angular/lib/core_dom/mustache.dart ('k') | third_party/pkg/angular/lib/core_dom/ng_mustache.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698