Due to #460 a .bridge method cant be directly added to class.interface.js.
Doing so, would create a circular reference because the device item (or at leas the _id property) needs to be passed into the interface instances. (The _id i used to tell the connector on which device + interface a connection needs to be established).
For that a injectMethod needs to be created, that add a property to the prototype of the given object.
(Which is absolutely the same as if the method was defined in the class body).
A test breaks when used for injecting the .bridge method into a interface instance.
Wihtout Object.getPrototype... it works. Otherwise only the last interface this method is used, create bridge requests.
Due to #460 a
.bridge
method cant be directly added toclass.interface.js
. Doing so, would create a circular reference because the device item (or at leas the_id
property) needs to be passed into the interface instances. (The _id i used to tell the connector on which device + interface a connection needs to be established).It would be better to inject/add the
.bridge
method for the interface instance in the fileclass.devcie.js
: https://github.com/OpenHausIO/backend/blob/b8f52009c0cf919ffe374b9b733e97d762b8224b/components/devices/class.device.js#L50For that a
injectMethod
needs to be created, that add a property to the prototype of the given object. (Which is absolutely the same as if the method was defined in the class body).This method could also be used in the
system/component
method definition: https://github.com/OpenHausIO/backend/blob/b8f52009c0cf919ffe374b9b733e97d762b8224b/system/component/class.common.js#L38-L41Instead of add a method to
this
, wrap it in theinjectMethod
method:injectMethod()
methodinjectMethod
to define.bridge()
method on interface instance (#460)[ ] Wrap component_defineMethod()
function definition ininjectMethod()