diff options
author | Carlo Zancanaro <carlo@zancanaro.id.au> | 2014-09-29 10:15:19 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@zancanaro.id.au> | 2014-09-29 10:15:19 +1000 |
commit | eeafd409cae5b1d22d9469fabef654d4c57b73f5 (patch) | |
tree | 6d97ba2550e9da47603e8e4aeeecd5e55c9c4233 /example/test.html | |
parent | fab0b505c608d2a553c1ca74553e6a433e453a5d (diff) |
A stupid little example
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 |