diff options
Diffstat (limited to 'example/test.html')
-rw-r--r-- | example/test.html | 70 |
1 files changed, 70 insertions, 0 deletions
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 |