From eeafd409cae5b1d22d9469fabef654d4c57b73f5 Mon Sep 17 00:00:00 2001
From: Carlo Zancanaro <carlo@zancanaro.id.au>
Date: Mon, 29 Sep 2014 10:15:19 +1000
Subject: A stupid little example

---
 example/test.html | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
 create mode 100644 example/test.html

(limited to 'example/test.html')

diff --git a/example/test.html b/example/test.html
new file mode 100644
index 0000000..00eed1b
--- /dev/null
+++ b/example/test.html
@@ -0,0 +1,70 @@
+<html>
+  <head>
+    <title>Dependency Injection on Steroids?</title>
+  </head>
+  <body>
+    <div>
+      <a href="#" onclick="create(0)">Create code main page</a>
+      <a href="#" onclick="destroy(0)">Destroy code main page</a>
+    </div>
+    <div>
+      <a href="#" onclick="create(1)">Create code main page</a>
+      <a href="#" onclick="destroy(1)">Destroy code main page</a>
+    </div>
+    <div id="content">This is some original content!</div>
+    <script src="../scorpion.js"></script>
+    <script src="jquery.js"></script>
+    <script>
+     var injector = new Scorpion([
+       Scorpion.prefixPlugin("dom!", new Scorpion.DOMPlugin()),
+       Scorpion.prefixPlugin("http!", new Scorpion.HTTPPlugin()),
+       new Scorpion.ValuePlugin()
+     ]);
+
+     injector.register("dom!main", "#content");
+     injector.register("http!main", "content.txt");
+
+     injector.register("Logger", function() {
+       console.log("logger!");
+       var requestor = this.requestor();
+       console.log("requestor!", requestor);
+       return {
+         log: function() {
+           return console.log.bind(console, requestor).apply(null, arguments);
+         }
+       };
+     });
+
+     injector.register("MainPage", ["dom!main", "http!main", "Logger", function(element, text, Logger) {
+       Logger.log("hello?");
+
+       var oldText = element.text();
+       element.text(text);
+
+       this.onDestroy = function() {
+         element.text(oldText);
+       }
+
+       return {};
+     }]);
+
+     var MainPage = [null, null];
+     window.create = function(i) {
+       if (!MainPage[i]) {
+         MainPage[i] = injector.get("MainPage");
+         MainPage[i].then(
+           console.log.bind(console, "resolved"),
+           console.log.bind(console, "rejected"));
+       }
+     };
+     window.destroy = function(i) {
+       if (MainPage[i]) {
+         MainPage[i].destroy();
+         MainPage[i] = null;
+       }
+     };
+    </script>
+  </body>
+</html>
+
+7451
-- 
cgit v1.2.3