Commit 4965eab4 authored by Romain Courteaud's avatar Romain Courteaud

Add declareAcquiredMethod.

Replace the gadget method "acquire" by the Klass function
"declareAcquiredMethod" which generates new accessors on this class and do a
direct mapping with the parent aq_dynamic function.
parent 52a76f99
...@@ -84,8 +84,12 @@ ...@@ -84,8 +84,12 @@
throw new Error("No element defined"); throw new Error("No element defined");
} }
return this.__element; return this.__element;
}) });
.declareMethod('acquire', function () {
/////////////////////////////////////////////////////////////////
// RenderJSGadget.declareAcquiredMethod
/////////////////////////////////////////////////////////////////
function acquire() {
var gadget = this, var gadget = this,
argument_list = arguments; argument_list = arguments;
return new RSVP.Queue() return new RSVP.Queue()
...@@ -102,7 +106,18 @@ ...@@ -102,7 +106,18 @@
} }
throw error; throw error;
}); });
}); }
RenderJSGadget.declareAcquiredMethod =
function (name, method_name_to_acquire) {
this.prototype[name] = function () {
return acquire.apply(this, [method_name_to_acquire,
Array.prototype.slice.call(arguments, 0)]);
};
// Allow chain
return this;
};
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// RenderJSEmbeddedGadget // RenderJSEmbeddedGadget
...@@ -270,7 +285,7 @@ ...@@ -270,7 +285,7 @@
return "OK"; return "OK";
}); });
gadget_instance.__chan.bind("acquire", function (trans, params) { gadget_instance.__chan.bind("acquire", function (trans, params) {
gadget_instance.acquire.apply(gadget_instance, params) acquire.apply(gadget_instance, params)
.then(function (g) { .then(function (g) {
trans.complete(g); trans.complete(g);
}).fail(function (e) { }).fail(function (e) {
...@@ -330,7 +345,7 @@ ...@@ -330,7 +345,7 @@
var i; var i;
// Define aq_parent to reach parent gadget // Define aq_parent to reach parent gadget
gadget_instance.aq_parent = function (method_name, argument_list) { gadget_instance.aq_parent = function (method_name, argument_list) {
return parent_gadget.acquire(method_name, argument_list); return acquire.apply(parent_gadget, [method_name, argument_list]);
}; };
// Drop the current loading klass info used by selector // Drop the current loading klass info used by selector
gadget_loading_klass = undefined; gadget_loading_klass = undefined;
...@@ -483,6 +498,8 @@ ...@@ -483,6 +498,8 @@
tmp_constructor.__ready_list = RenderJSGadget.__ready_list.slice(); tmp_constructor.__ready_list = RenderJSGadget.__ready_list.slice();
tmp_constructor.declareMethod = tmp_constructor.declareMethod =
RenderJSGadget.declareMethod; RenderJSGadget.declareMethod;
tmp_constructor.declareAcquiredMethod =
RenderJSGadget.declareAcquiredMethod;
tmp_constructor.ready = tmp_constructor.ready =
RenderJSGadget.ready; RenderJSGadget.ready;
tmp_constructor.prototype = new RenderJSGadget(); tmp_constructor.prototype = new RenderJSGadget();
...@@ -635,6 +652,8 @@ ...@@ -635,6 +652,8 @@
RenderJSGadget.call(this); RenderJSGadget.call(this);
}; };
tmp_constructor.declareMethod = RenderJSGadget.declareMethod; tmp_constructor.declareMethod = RenderJSGadget.declareMethod;
tmp_constructor.declareAcquiredMethod =
RenderJSGadget.declareAcquiredMethod;
tmp_constructor.__ready_list = RenderJSGadget.__ready_list.slice(); tmp_constructor.__ready_list = RenderJSGadget.__ready_list.slice();
tmp_constructor.ready = RenderJSGadget.ready; tmp_constructor.ready = RenderJSGadget.ready;
tmp_constructor.prototype = new RenderJSGadget(); tmp_constructor.prototype = new RenderJSGadget();
...@@ -713,6 +732,9 @@ ...@@ -713,6 +732,9 @@
return result; return result;
}; };
tmp_constructor.declareAcquiredMethod =
RenderJSGadget.declareAcquiredMethod;
// Define aq_parent to inform parent window // Define aq_parent to inform parent window
tmp_constructor.prototype.aq_parent = function (method_name, tmp_constructor.prototype.aq_parent = function (method_name,
argument_list) { argument_list) {
......
...@@ -24,8 +24,14 @@ ...@@ -24,8 +24,14 @@
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
return this.embedded_property; return this.embedded_property;
}) })
.declareMethod('callAcquire', function (method_name, param_list) { .declareAcquiredMethod('plugOKAcquire', 'acquireMethodRequested')
return this.acquire(method_name, param_list); .declareMethod('callOKAcquire', function (param1, param2) {
return this.plugOKAcquire(param1, param2);
})
.declareAcquiredMethod('plugErrorAcquire',
'acquireMethodRequestedWithAcquisitionError')
.declareMethod('callErrorAcquire', function (param1, param2) {
return this.plugErrorAcquire(param1, param2);
}); });
}(window, rJS)); }(window, rJS));
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment