Browse files

@Initialize for wire added

  • Loading branch information...
1 parent 7271e52 commit 07578db069c63853b27bd118808b242c331287f6 @warmuuh committed Mar 18, 2013
View
3 .scripted
@@ -6,6 +6,7 @@
}
},
"jshint" : {
- options: {node: true, white:false}
+ options: {node: true, white:false},
+ "global" : ["console", "define", "exports", "module", "require"]
}
}
View
29 node-example/MyClass.js
@@ -1,28 +1,37 @@
+"use strict";
-function MyClass (val){
+function MyClass(val) {
this.value = val;
}
MyClass.prototype = {
- doSomething: function( /*@Default("Default Message")*/msg, /*@Autowired("message")*/msg2, /*@Autowired*/message) {
- 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) {
+ console.log("default: " + msg);
+ console.log("wired: " + this.value);
+ console.log("autowired: " + msg2);
+ console.log("autowired(pname): " + message);
},
- doSomethingElse: function( msg) /*@NotNull*/{
- console.log(msg + " " +this.value);
+ doSomethingElse: function (msg) /*@NotNull*/{
+ console.log(msg + " " + this.value);
},
- doSomethingElseAgain: function( message) /*@Autowired*/{
- console.log("autowired(fn): " + message );
+ doSomethingElseAgain: function (message) /*@Autowired*/{
+ console.log("autowired(fn): " + message);
},
+ onInit: function (message)
+ /* @Autowired @Initialize */
+ {
+ console.log("autowired init fn: " + message);
+ }
};
View
11 yaap/test/classes/InitializeTest.js
@@ -0,0 +1,11 @@
+"use strict";
+module.exports = {
+ fn1: function() /*@Initialize*/
+ {
+ this.value = 1;
+ },
+ fn2: function(bean)/*@Autowired @Initialize*/
+ {
+ this.bean = bean;
+ }
+};
View
16 yaap/test/wire.js
@@ -33,5 +33,21 @@ module.exports = {
test.equal(ctx.testInstance.fn3(), ctx.bean);
test.done();
}, console.error);
+ },
+ "wiring with @Initialize": function(test){
+
+ var spec = {
+ bean: "autowiredValue",
+ testInstance:{create: './classes/InitializeTest'},
+ plugins: [//{module: "wire/debug", trace: true},
+ {module:'../wire'}]
+ };
+
+ wire(spec, {require:require}).then(function(ctx){
+ test.equal(ctx.testInstance.bean, ctx.bean);
+ test.equal(ctx.testInstance.value, 1);
+ test.done();
+ }, console.error);
}
+
};
View
1 yaap/wire/plugins/AutowireProcessor.js
@@ -68,7 +68,6 @@ return {
});
when.map(refs, cfg.wire).then(function (resolvedRefs){
- //console.log("1");
var origFn = obj[fnObj.name];
obj[fnObj.name] = function(){
View
46 yaap/wire/plugins/InitializeProcessor.js
@@ -0,0 +1,46 @@
+/** @license MIT License (c) copyright 2013 original author or authors */
+
+/**
+ * @Autowired annotation processor.
+ *
+ * Autowires parameters of function calls based on a given or the parameter name.
+ *
+ * needs wire to be in the configuration object.
+ *
+ *
+ * Licensed under the MIT License at:
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * @author Peter Mucha
+ *
+ * @version 0.0.3
+ */
+"use strict";
+(function(define) {
+define([],
+function() {
+
+
+var registeredInitializers = [];
+
+
+return {
+ annotation: "@Initialize",
+
+
+
+ processFunction: function(obj, fnObj, annotationParams, cfg){
+
+
+ registeredInitializers.push({obj: obj, name: fnObj.name});
+ },
+
+ afterProcessing: function(obj){
+ while(registeredInitializers.length > 0){
+ var init = registeredInitializers.pop();
+ init.obj[init.name](); //call it
+ }
+ }
+};
+
+});})(typeof define == 'function'? define: function(deps, factory) {module.exports = factory.apply(this, deps.map(function(x) {return require(x);}));});
View
16 yaap/wire/wireplugin.js
@@ -10,20 +10,26 @@
* http://www.opensource.org/licenses/mit-license.php
*/
(function(define) {
- define(["underscore", "../yaap", "./plugins/AutowireProcessor", "wire"], function(_, yaap, autowire, wire) {
+ define(["underscore", "../yaap", "./plugins/AutowireProcessor", "./plugins/InitializeProcessor", "wire"], function(_, yaap, autowire, initialize, wire) {
"use strict";
- function annotatesFacet(resolver, facet, wire) {
+ function annotatesFacet(resolver, facet, wire) {
var options = facet.options;
var obj = facet.target;
yaap.process(obj, {
wire: wire
});
resolver.resolve();
+
+
}
-
+ function afterProcessing(resolver, facet, wire) {
+ //TODO: find more decoupled solution
+ initialize.afterProcessing(facet.target);
+ resolver.resolve();
+ }
@@ -32,9 +38,11 @@
wire$plugin: function(ready, destroyed, options) {
yaap.register(autowire); //register annotation processor for @Autowire
+ yaap.register(initialize); //register annotation processor for @Initialize
return {
- initialize: annotatesFacet
+ configure: annotatesFacet,
+ "ready": afterProcessing
};
}
};
View
7 yaap/yaap.js
@@ -50,6 +50,9 @@ function(_, registry, NotNullProcessor, DefaultProcessor, wire, PanPG_util, es5,
});
+
+
+
};
@@ -61,7 +64,7 @@ function(_, registry, NotNullProcessor, DefaultProcessor, wire, PanPG_util, es5,
register: function (processor) {
registry.register([processor]);
},
-
+
process: function (obj, config){
var functions = _(obj).functions();
_(functions).each(function(f){
@@ -91,7 +94,7 @@ function(_, registry, NotNullProcessor, DefaultProcessor, wire, PanPG_util, es5,
return obj;
}
- }
+ };

0 comments on commit 07578db

Please sign in to comment.