summaryrefslogtreecommitdiff
path: root/example/test.html
blob: 00eed1b2feb1f08a029ccfd049d5b71b83bf12ae (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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