Permalink
Browse files

fixed deferred reference-resolving

  • Loading branch information...
warmuuh committed Apr 2, 2013
1 parent bdbaf17 commit 38b3a698fbab7d9d4d88c469bbf4332c2c671ce1
View
@@ -8,4 +8,24 @@ See [Readme](yaap/README.md) for more information.
There are also two examples for server and client scenario:
* On [Node](node-example)
-* In [Browser](browser-example)
+* In [Browser](browser-example)
+
+
+#News
+
+
+##master
+* New Wire-Annotations: `@PostConstruct`, `@PreDestroy` ([more information](yaap/docs/annotation.md))
+* New Browser-specific Wire-Annotation: `@On` (for eventbinding) ([more information](yaap/docs/annotation.md))
+* Performance Improvements
+* Rearranged plugin-api
+* yaap/wire-plugins can promise now (and must, in case of deferred reference-resolving) ([more information](yaap/docs/processors.md))
+
+
+##0.0.2
+* browser-compatibility (available in `bower`)
+
+##0.0.1
+* Yaap Annotation processor
+* Initial Annotations: `@Default`, `@NotNull`
+* Initial Wire-specific Annotations: `@Autowired`
View
@@ -6,14 +6,11 @@ function MyClass (val){
MyClass.prototype = {
- doSomething: function( /*@Default("Default Message")*/msg, /*@Autowired("message")*/msg2, /*@Autowired*/message) {
- //console.log( node );
- //output.value = "default: " +msg +"\n";
- console.log("default: " +msg);
- console.log("wired: " + this.value );
- console.log("autowired: " +msg2 );
- console.log("autowired(pname): " + message );
-
+ doSomething: function( /*@Default("Default Message")*/msg, /*@Autowired("message")*/msg2, /*@Autowired*/message, /*@Autowired("out")*/output) {
+ output.value = "default: " +msg +"\n";
+ output.value +="wired: " + this.value +"\n";
+ output.value +="autowired: " +msg2 +"\n";
+ output.value +="autowired(pname): " + message +"\n";
},
@@ -22,10 +19,10 @@ MyClass.prototype = {
},
- onNodeClick: function( e )
+ onNodeClick: function( e, /*@Autowired*/node )
/* @On("node", "click") */
{
- alert("you clicked the button: " + e.target.value); // + node);
+ alert("you clicked the button: " + e.target.value + "\nNode:" + node); // + node);
}
};
@@ -26,7 +26,7 @@
<body>
<input class="pressed" type="button" id="myButton" value="Button1" />
<input class="pressed" type="button" id="myButton" value="Button2" />
-<textarea style="display:block;width:200px;height:200px" id="output"></textarea>
+<textarea style="display:block;width:500px;height:200px" id="output"></textarea>
<script src="./components/curl/src/curl.js"></script>
<script type="text/javascript">
View
@@ -4,7 +4,7 @@ define([], function(){
return {
message: "autowired",
node: {$ref: "dom.all!.pressed"},
- //out: {$ref: "dom!output"},
+ out: {$ref: "dom!output"},
myComponent: {
create: {
module: 'MyClass',
View
@@ -15,8 +15,8 @@ Installation for node: `npm install yaap`
##Articles
-[Annotations for JavaScript](http://cubiccow.blogspot.com/2013/02/yaap-annotations-for-javascript.html)
-[@Autowired for JavaScript](http://cubiccow.blogspot.de/2013/02/autowire-for-javascript.html)
+* [Annotations for JavaScript](http://cubiccow.blogspot.com/2013/02/yaap-annotations-for-javascript.html)
+* [@Autowired for JavaScript](http://cubiccow.blogspot.de/2013/02/autowire-for-javascript.html)
##Example
View
@@ -23,11 +23,11 @@ Some annotations can only be used on parameters while others can also be used at
* `@PreDestroy` (function): the annotated function will be called, if context.destroy() is called.
###browser-specific wire annotations
+for these annotations, you need to add the additional `yaao/wire/html`-plugin!
* `@On(<refName>, <event>)` (function): the annotated function will automatically be bound the the event of the given dom-node.
This is intended to be used with the `wire/dom`-plugin. <refName> can reference one or more elements in the dom (though
it is probably better practice to reference a bean in the wirecontext, which itself references the dom-nodes).
For example, you could bind a clickhandler with this annotation: `@On("dom.all!.btn","click")`.
- The annotated method accepts one argument that is the event.
- `Remark:` still work in process
+ The annotated method accepts one argument that is the event (though you could add additional @autowired arguments, if you want)
View
@@ -9,15 +9,15 @@ The "annotation" property defines the name of your annotation. The following exa
```js
var myProcessor = {
annotation: "@NotNull",
- processFunction: function(object, fnDescription, annotationParams, configuration){... },
- processParameter: function(object, fnDescription, annotatedParameters, configuration){...}
+ processFunction: function(object, fnDescription, annotationParams, context){... },
+ processParameter: function(object, fnDescription, annotatedParameters, context){...}
}
yaap.register(myProcessor);
```
The last line registers the processor at yaap. The annotation is now ready to be used.
-The configuration object can be supplied as argument to yaap.process so you could hand over some dependencies to the annotation processors.
+The context object can be supplied as argument to yaap.process so you could hand over some dependencies to the annotation processors. (currently, its used for wire-specific processors).
#Process Functions
@@ -54,3 +54,12 @@ The parameters are handed over as array instead of multiple calls to "processPar
because then you can handle each annotated parameter in one wrapper of the target function
instead of one separate handler for each annotated parameter.
+##Wire-Specific Processors
+Wire-specific processors need a specific instance of wire to e.g. resolve references in the current context.
+Therefore the context contains the wire-context as well as an array where plugins can put their promises. The context object looks loke this:
+```js
+{
+wire: ...,
+promises: []
+}
+```
View
@@ -26,9 +26,9 @@ return {
register: function(processors){
_(processors).each(function(proc){
registry.push(proc);
- })
+ });
}
-}
+};
});})(typeof define == 'function'? define: function(deps, factory) {module.exports = factory.apply(this, deps.map(function(x) {return require(x);}));});
@@ -17,15 +17,18 @@
*/
"use strict";
(function(define) {
-define([ "wire/on"],
-function(on) {
+define([ "wire/on", "when"],
+function(on, when) {
return {
annotation: "@On",
processFunction: function(obj, fnDescription, annotationParams, context){
var wire = context.wire;
+
+ var promise = when.defer();
+ context.promises.push(promise.promise);
wire.resolveRef(annotationParams[0]).then(function(nodeRef){
if( nodeRef.length && nodeRef.length > 0 ) {
@@ -38,8 +41,9 @@ return {
on(nodeRef, annotationParams[1], function(evt){
obj[fnDescription.name](evt); //dynamic call because there could be other annotations
});
-
- });
+
+ promise.resolve();
+ }, promise.reject);
}
};
@@ -24,8 +24,7 @@ function(_, when) {
return {
annotation: "@Autowired",
processParameter: function(obj, fnDescription, annotatedParameters, context) {
- //console.log("@Autowired("+ annotationParams +") attached at parameter: " + param.name);
-
+
var refs = {};
for(var i = 0; i < annotatedParameters.length; ++i){
@@ -37,8 +36,9 @@ return {
refs[param.name] = {$ref: refName};
}
+ var promise = when.defer();
+ context.promises.push(promise.promise);
context.wire(refs).then(function (resolvedRefs) {
-
var origFn = obj[fnDescription.name];
@@ -60,10 +60,13 @@ return {
default: return origFn.apply(obj, arguments);
}
};
+
+ promise.resolve();
},
function(err){
console.error("@Autowired failed: " + err);
+ promise.reject();
});
},
@@ -76,6 +79,8 @@ return {
return {$ref: param.name};
});
+ var promise = when.defer();
+ context.promises.push(promise.promise);
when.map(refs, context.wire).then(function (resolvedRefs){
var origFn = obj[fnDescription.name];
@@ -95,10 +100,14 @@ return {
case 3: return origFn.call(obj, arguments[0], arguments[1], arguments[2]);
default: return origFn.apply(obj, arguments);
}
+
};
+ promise.resolve();
-
- }, function(err){console.error(err);});
+ }, function(err){
+ console.error(err);
+ promise.reject();
+ });
}
};
View
@@ -14,19 +14,21 @@
"./plugins/AutowireProcessor",
"./plugins/PostConstructProcessor",
"./plugins/PreDestroyProcessor",
- "wire"], function(_, yaap, autowire, postConstruct, preDestroy, wire) {
+ "wire", "when"], function(_, yaap, autowire, postConstruct, preDestroy, wire, when) {
"use strict";
function processAnnotations(resolver, facet, wire) {
var options = facet.options;
var obj = facet.target;
- yaap.process(obj, {
- wire: wire //feed in context, so Autowire can do its work
- });
- resolver.resolve();
-
+ var ctx = {
+ wire: wire, //feed in context, so Autowire can do its work
+ promises: [] //plugins can save promises here
+ };
+ yaap.process(obj, ctx);
+
+ when.all(ctx.promises).then(resolver.resolve,resolver.reject);
}
function afterProcessing(resolver, facet, wire) {

0 comments on commit 38b3a69

Please sign in to comment.