Skip to content

Commit

Permalink
Major refactoring of object creation and initialization using an init…
Browse files Browse the repository at this point in the history
… queue. Better reference resolution. Experimental rest plugin that can resolve references to rest resources
  • Loading branch information
briancavalier committed Dec 27, 2010
1 parent a1dac98 commit 55bc3c8
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 141 deletions.
7 changes: 4 additions & 3 deletions index.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// Pick either the AlertLogger or SilentLogger and reload. // Pick either the AlertLogger or SilentLogger and reload.
// Can inject concrete dependencies without having to modify Controller. // Can inject concrete dependencies without having to modify Controller.
logger: { logger: {
module: 'test/test1/AlertLogger' module: 'test/test1/ConsoleLogger'
}, },


// Silly, but shows that native values can be declared as usual, and can be wired in // Silly, but shows that native values can be declared as usual, and can be wired in
Expand Down Expand Up @@ -55,7 +55,8 @@
number: { "$ref": "number" }, number: { "$ref": "number" },
// logger: { "$ref": "logger" }, // logger: { "$ref": "logger" },
messageNode: { "$ref" : "dom!node1" }, // inject reference to dom node by id messageNode: { "$ref" : "dom!node1" }, // inject reference to dom node by id
foo: { "$ref": "foo" } foo: { "$ref": "foo" },
logger: { $ref: "logger" }
}, },
// Init function (named "ready") will be called after on DomReady // Init function (named "ready") will be called after on DomReady
// Allows > 1 function to be called // Allows > 1 function to be called
Expand All @@ -67,7 +68,7 @@
} }
}, },
function(context2) { function(context2) {
console.log(context2.get("controller").foo); console.log(context2.get("controller"));
}); });
}); });
</script> </script>
Expand Down
22 changes: 22 additions & 0 deletions rest1.html
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Launcher test</title>
<script type="text/javascript">
djConfig = {
baseUrl: './',
modulePaths: {
'dojo': 'dojo',
'dijit': 'dijit',
'test': 'test'
}
};
</script>
<script src="require.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="wire.js" data-wire-spec="rest1.js"></script>
</head>
<body>

</body>
</html>
28 changes: 28 additions & 0 deletions rest1.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,28 @@
wire({
wire$plugins: [
{ module: 'wire/rest' }
],
controller: {
module: 'test/rest1/Controller',
create: [],
properties: {
store: { '$ref': 'rest!test/rest1/person.json' }
},
init: 'ready'
},
controller2: {
module: 'test/rest1/Controller',
create: [],
properties: {
store: {
module: 'dojo/store/JsonRest',
create: [{ target: 'test/rest1/person.json' }]
}
},
init: 'ready'
}
},
function(context) {
console.log(context.get('controller'));
console.log(context.get('controller2'));
});
13 changes: 13 additions & 0 deletions test/rest1/Controller.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,13 @@
define([], function() {

var Controller = function() {
};

Controller.prototype.ready = function() {
this.store.query({}).forEach(function(person) {
console.log(person);
});
};

return Controller;
});
10 changes: 10 additions & 0 deletions test/rest1/person.json
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"id": 1,
"name": "Sergei Rachmaninoff"
},
{
"id": 2,
"name": "Dmitri Bortnianski"
}
]
2 changes: 1 addition & 1 deletion test/test1/Controller.js
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['test/test1/ConsoleLogger'], function(defaultLogger) { define(['test/test1/AlertLogger'], function(defaultLogger) {


var Controller = function(name) { var Controller = function(name) {
// Defaults, these will get rewired // Defaults, these will get rewired
Expand Down
16 changes: 10 additions & 6 deletions test2.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ wire({
// dom: { module: 'wire/dom' } // dom: { module: 'wire/dom' }
// This seems like it could end up being a reasonable convention, tho. // This seems like it could end up being a reasonable convention, tho.
wire$plugins: [ wire$plugins: [
{ module: 'dojo' },
{ module: 'dijit/form/TextBox' }, { module: 'dijit/form/TextBox' },
{ module: 'wire/dijit' }, // Calls dojo.parser.parse { module: 'wire/dijit' }, // Calls dojo.parser.parse
{ module: 'wire/dom' } { module: 'wire/dom' }
Expand All @@ -16,16 +15,21 @@ wire({
module: 'test/test2/Controller', module: 'test/test2/Controller',
create: [], create: [],
properties: { properties: {
name: "controller1", name: { '$ref': 'name' },
widget: { widget: { '$ref': 'widget1' }
module: 'dijit/form/TextBox',
create: [{}, { $ref: 'dom!widgetNode' }]
}
}, },
init: { init: {
ready: [] ready: []
} }
}, },
name: 'controller1',
widget1: {
module: 'dijit/form/TextBox',
create: [{}, { $ref: 'dom!widgetNode' }],
properties: {
value: "Initial Value!"
}
},
// Create a controller, and inject a dijit.form.TextBox that is simply // Create a controller, and inject a dijit.form.TextBox that is simply
// referenced using the dijit resolver // referenced using the dijit resolver
controller2: { controller2: {
Expand Down
Loading

0 comments on commit 55bc3c8

Please sign in to comment.