gildor
10/31/2017, 9:19 AMmodule.exports.myFunctionName = functions.https.onRequest(myFunction)
//instead of https.onRequest can be other function builder
So looks like I can just declare top level public property with this firebase function builder:
val myFunctionName = functions.https.onRequest(myFunction)
Generated code looks like:
(function (_, Kotlin, $module$firebase_functions) {
'use strict';
var println = Kotlin.kotlin.io.println_s8jyv4$;
var Unit = Kotlin.kotlin.Unit;
function myFunctionName$lambda() {
println('Triggered!');
return Unit;
}
var myFunctionName;
Object.defineProperty(_, 'myFunctionName', {
get: function () {
return myFunctionName;
}
});
myFunctionName = $module$firebase_functions.https.onRequest(myFunctionName$lambda);
Kotlin.defineModule('index', _);
return _;
}(module.exports, require('kotlin'), require('firebase-functions')));
So, Kotlin defines propery in module.exports, looks like valid way and can be used if you run module.exports.myFunctionName()
But unfortunately this approach doesn’t work with firebase functions, because defined property is not in modules list.
This is reproduction of this behaviour in JS:
var myFunctionName = function() { console.log("Triggered") }
Object.defineProperty(module.exports, 'doSomething', {
get: function () {
return myFunctionName;
}
});
console.log(module.exports.doSomething); // [Function: myFunctionName] -- looks like everything is fine
console.log(module.exports) // {} -- but modules are empty
module.exports.doSomethingModule = myFunctionName // Declare another module directly
console.log(module.exports.doSomethingModule); // [Function: myFunctionName] -- same result as for module.exports.doSomething
console.log(module.exports) // { doSomethingModule: [Function: myFunctionName] } -- but now module is visible in list of all modules
So, looks like Firebase get list of registered modules from module.exports.
I understand that it’s specific case, but maybe it can be somehow resolved without manual module registration using external val module: dynamic
konsoletyper
10/31/2017, 9:25 AMkonsoletyper
10/31/2017, 9:26 AMgildor
10/31/2017, 9:32 AMenumerable: true
for such properties.
Just curious which solution do you prefer?konsoletyper
10/31/2017, 9:35 AMnapperley
11/01/2017, 5:32 AMgildor
11/01/2017, 6:24 AMnapperley
11/01/2017, 6:28 AMgildor
11/01/2017, 6:38 AM