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

Unified Diff: sky/examples/fn/lib/fakesky.dart

Issue 971183002: Initial commit of Effen reactive framework experiment for Sky (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « sky/examples/fn/lib/component.dart ('k') | sky/examples/fn/lib/fn.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/fn/lib/fakesky.dart
diff --git a/sky/examples/fn/lib/fakesky.dart b/sky/examples/fn/lib/fakesky.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c2c72315d769bce43e70f0f0c77c094ff1fee57c
--- /dev/null
+++ b/sky/examples/fn/lib/fakesky.dart
@@ -0,0 +1,148 @@
+import 'dart:async';
+
+void assertHasParentNode(Node n) { assert(n.parentNode != null); }
+void assertHasParentNodes(List<Node> list) {
+ for (var n in list) {
+ assertHasParentNode(n);
+ }
+}
+
+class Node {
+
+ ParentNode parentNode;
+ Node nextSibling;
+ Node previousSibling;
+ Node();
+
+ void insertBefore(List<Node> nodes) {
+ int count = nodes.length;
+ while (count-- > 0) {
+ parentNode._insertBefore(nodes[count], this);
+ }
+
+ assertHasParentNodes(nodes);
+ }
+
+ remove() {
+ if (parentNode == null) {
+ return;
+ }
+
+ if (nextSibling != null) {
+ nextSibling.previousSibling = previousSibling;
+ } else {
+ parentNode.lastChild = previousSibling;
+ }
+
+ if (previousSibling != null) {
+ previousSibling.nextSibling = nextSibling;
+ } else {
+ parentNode.firstChild = nextSibling;
+ }
+
+ parentNode = null;
+ nextSibling = null;
+ previousSibling = null;
+ }
+}
+
+class Text extends Node {
+ String data;
+ Text(this.data) : super();
+}
+
+class ParentNode extends Node {
+ Node firstChild;
+ Node lastChild;
+
+ ParentNode() : super();
+
+ Node setChild(Node node) {
+ firstChild = node;
+ lastChild = node;
+ node.parentNode = this;
+ assertHasParentNode(node);
+ return node;
+ }
+
+ Node _insertBefore(Node node, Node ref) {
+ assert(ref == null || ref.parentNode == this);
+
+ if (node.parentNode != null) {
+ node.remove();
+ }
+
+ node.parentNode = this;
+
+ if (firstChild == null && lastChild == null) {
+ firstChild = node;
+ lastChild = node;
+ } else if (ref == null) {
+ node.previousSibling = lastChild;
+ lastChild.nextSibling = node;
+ lastChild = node;
+ } else {
+ if (ref == firstChild) {
+ assert(ref.previousSibling == null);
+ firstChild = node;
+ }
+ node.previousSibling = ref.previousSibling;
+ ref.previousSibling = node;
+ node.nextSibling = ref;
+ }
+
+ assertHasParentNode(node);
+ return node;
+ }
+
+ Node appendChild(Node node) {
+ return _insertBefore(node, null);
+ }
+}
+
+class Element extends ParentNode {
+ void addEventListener(String type, EventListener listener, [bool useCapture = false]) {}
+ void removeEventListener(String type, EventListener listener) {}
+ void setAttribute(String name, [String value]) {}
+}
+
+class Document extends ParentNode {
+ Document();
+ Element createElement(String tagName) {
+ switch (tagName) {
+ case 'img' : return new HTMLImageElement();
+ default : return new Element();
+ }
+ }
+}
+
+class HTMLImageElement extends Element {
+ Image();
+ String src;
+ Object style = {};
+}
+
+class Event {
+ Event();
+}
+
+typedef EventListener(Event event);
+
+void _callRAF(Function fn) {
+ fn(new DateTime.now().millisecondsSinceEpoch.toDouble());
+}
+
+class Window {
+ int requestAnimationFrame(Function fn) {
+ new Timer(const Duration(milliseconds: 16), () {
+ _callRAF(fn);
+ });
+ }
+
+ void cancelAnimationFrame(int id) {
+ }
+}
+
+Document document = new Document();
+
+Window window = new Window();
« no previous file with comments | « sky/examples/fn/lib/component.dart ('k') | sky/examples/fn/lib/fn.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698