Permalink
Browse files

Interim commit. Still some work to do on when.js 0.10.0 compat

  • Loading branch information...
briancavalier committed Nov 5, 2011
1 parent daea1e7 commit 791a02e422efd02898beb651fa3ac172c4fea826
Showing with 192 additions and 36 deletions.
  1. +12 −11 test/basic-types1.html
  2. +1 −1 test/dojo/dijit1.html
  3. +1 −1 test/dojo/dijit1.js
  4. +2 −6 test/dojo/events1.html
  5. +5 −2 test/dojo/events2.html
  6. +81 −0 test/init-error.html
  7. +4 −4 test/nested1.html
  8. +41 −0 test/nested3.html
  9. +45 −11 wire.js
View
@@ -11,37 +11,38 @@
// Simple example of wiring in objects by reference using JSON ref syntax
require(['wire'], function(wire) {
wire({
+ debug: { module: 'wire/debug' },
// Order doesn't matter. Forward refs are ok
- numberRef: { $ref: 'number' },
- objectRef: { $ref: 'object' },
+// numberRef: { $ref: 'number' },
+// objectRef: { $ref: 'object' },
// Plain strings and numbers
string: 'this is a string',
- number: 10,
+// number: 10,
// Builtins that look like objects are supported directly
- date: new Date(),
+// date: new Date(),
- regex1: /^blah$/,
- regex2: new RegExp("^foobar$"),
+// regex1: /^blah$/,
+// regex2: new RegExp("^foobar$"),
- boolean1: true,
- boolean2: new Boolean(false),
+// boolean1: true,
+// boolean2: new Boolean(false),
// As are plain objects, which also provide scoping
object: {
- string: "I'm a nested a string",
+// string: "I'm a nested a string",
nested: {
// Will reference object.string rather than
// the top-level string because of scoping.
nameRef: { $ref: 'string' },
string: { $ref: 'string' }
}
- },
+ }
// Arrays are easy, too
- array: ["string", 10, { foo: "bar" }, [1, 2, 3], { a: [1, 2, 3], b: 4 }]
+// array: ["string", 10, { foo: "bar" }, [1, 2, 3], { a: [1, 2, 3], b: 4 }]
}).then(
function(context) {
function tos(it) {
View
@@ -25,7 +25,7 @@
</script>
<script type="text/javascript">
- require(['curl/dojo16Compat']).next(['wire!test/dojo/dijit1'], function(context) {
+ require(['curl/dojo16Compat', 'dijit/form/TextBox']).next(['wire!test/dojo/dijit1'], function(context) {
// Properties/objects from the parent context are available via the prototype!
console.log("initialValue", context.initialValue);
View
@@ -5,7 +5,7 @@ define({
// dom: { module: 'wire/dom' }
// This seems like it could end up being a reasonable convention, tho.
plugins: [
-// { module: 'wire/debug' },
+ { module: 'wire/debug' },
{ module: 'wire/dojo/dijit', parse: true }, // Calls dojo.parser.parse
{ module: 'wire/dom', classes: { init: 'loading' } }
],
View
@@ -22,6 +22,7 @@
require(['curl/dojo16Compat']).next(['wire'], function(wire) {
wire({
plugins: [
+ { module: 'wire/debug' },
{ module: 'wire/dojo/events' },
{ module: 'wire/dom' }
],
@@ -30,12 +31,6 @@
// since the module doesn't return a function (constructor or otherwise)
// that can be invoked--it returns an object.
module: "handler",
- properties: {
- // wire provides a way to wire in the enclosing context
- // itself. This can be useful in certain situations, although
- // in general, you shouldn't need to.
- "context": { $ref: "wire!context" }
- },
// Use the wire/dojo/events plugin to declare that when the
// #test button is clicked, handler's handleEvent method will
// be called.
@@ -47,6 +42,7 @@
}
}).then(
function(context) {
+ context.handler.context = context;
console.log("Done", context);
},
function(err) {
View
@@ -12,7 +12,7 @@
return {
handleEvent: function(e) {
e.target.innerHTML = "Success!";
- this.context.then(function(c) { c.destroy(); });
+ this.context.destroy();
}
};
});
@@ -21,7 +21,7 @@
return {
handleEvent: function(e) {
e.target.innerHTML = "Success!";
- this.context.then(function(c) { c.destroy(); });
+ this.context.destroy();
}
};
});
@@ -55,6 +55,7 @@
}
}).then(
function(context) {
+ context.handler.context = context;
console.log("Done", context);
context.wire({
plugins: [
@@ -84,6 +85,8 @@
}
}).then(
function(child) {
+ child.handler.context = context;
+
console.log("Child done", child);
}
);
View
@@ -0,0 +1,81 @@
+<!DOCTYPE HTML>
+<html lang="en-US">
+<head>
+ <meta charset="UTF-8">
+ <title>Init error test</title>
+
+ <script src="util/doh/runner.js"></script>
+ <script src="test-config.js"></script>
+
+ <script type="text/javascript">
+
+ function error(p) {
+ throw new Error();
+ }
+
+ define('init-error', [], function() {
+ function Constructor() {}
+
+ Constructor.prototype = {
+ init: error
+ };
+
+ return Constructor;
+ });
+
+ define('test-plugin', function() {
+ return {
+ wire$plugin: function() {
+ return {
+ facets: {
+ error: {
+// create: error,
+// configure: error
+// initialize: error
+ ready: error
+ }
+ }
+
+ }
+ }
+ }
+ });
+
+ require(['wire'], function(wire) {
+ doh.register('init-error', [
+ function(doh) {
+ var dohd = new doh.Deferred();
+
+ wire({
+ plugins: [
+// { module: 'wire/debug' },
+ { module: 'test-plugin' }
+ ],
+ // test1 should should be called as a constructor using new
+ test: {
+ create: 'init-error',
+ error: 'init'
+ }
+ }).then(
+ function(context) {
+ console.log(context);
+ console.error(context);
+ dohd.errback('wire() should not have succeeded');
+ },
+ function(err) {
+ dohd.callback(true);
+ }
+ );
+
+ return dohd;
+
+ }
+ ]);
+
+ doh.run();
+ });
+ </script>
+</head>
+<body>
+</body>
+</html>
View
@@ -17,9 +17,9 @@
require(['wire'], function(wire) {
wire({
// Plugins
- // plugins: [
- // { module: 'wire/debug' }
- // ],
+ plugins: [
+ { module: 'wire/debug' }
+ ],
// The particular logger we want.
// Pick either the AlertLogger or SilentLogger and reload.
// Can inject concrete dependencies without having to modify Controller.
@@ -48,7 +48,7 @@
context.wire({
// Plugins
plugins: [
- // { module: 'wire/debug' },
+ { module: 'wire/debug' },
{ module: 'wire/dom' }
],
name: "Test 2",
View
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML>
+<html lang="en-US">
+<head>
+ <meta charset="UTF-8">
+ <title>NExted types test</title>
+
+ <script src="util/doh/runner.js"></script>
+ <script src="test-config.js"></script>
+
+ <script type="text/javascript">
+ // Simple example of wiring in objects by reference using JSON ref syntax
+ require(['wire'], function(wire) {
+ wire({
+ debug: { module: 'wire/debug' },
+ a: 'a',
+ object: {
+ nameRef: { $ref: 'a' },
+ b: { $ref: 'a' }
+ }
+ }).then(
+ function(context) {
+ doh.register('nested', [
+ function (doh) {
+// doh.assertEqual(context.a, context.object.nested.a);
+ }
+ ]);
+
+ doh.run();
+
+ },
+ function(err) {
+ console.error(err);
+ }
+ );
+
+ });
+ </script>
+</head>
+<body>
+</body>
+</html>
Oops, something went wrong.

0 comments on commit 791a02e

Please sign in to comment.