lewik
10/16/2017, 4:20 PMexternal
declarations, that will allow to work with plain js objects and arrays without adding anything to js code. Allow to use js arrays in kotlin - iterate and so on.nomad
10/16/2017, 4:50 PMlewik
10/17/2017, 8:17 AMget
, external class should help?nomad
10/17/2017, 8:52 AMDaniel Illescas
10/17/2017, 10:50 AM<script src=“/Users/Daniel/Documents/IntelliJ IDEA/EverythingKT/node_modules/kotlin/kotlin.js” charset=“UTF-8"></script>
<script src=“/Users/Daniel/Documents/IntelliJ IDEA/EverythingKT/node_modules/kotlin/kotlin.meta.js” charset=“UTF-8"></script>
Daniel Illescas
10/17/2017, 11:04 AMmmaillot
10/17/2017, 11:45 AMkarelpeeters
10/17/2017, 4:55 PMverachadw
10/18/2017, 5:00 AMAetet
10/18/2017, 5:03 PMDanilo
10/19/2017, 5:57 PMthesheps
10/19/2017, 6:29 PMthesheps
10/19/2017, 7:20 PMSlackbot
10/20/2017, 11:33 PMmichael salmon
10/25/2017, 9:40 AMgaetan
10/25/2017, 10:57 AMnomad
10/25/2017, 2:33 PMjasper
10/26/2017, 5:02 AMhiperbou
10/27/2017, 12:29 PMuliluckas
10/29/2017, 12:30 PMgildor
10/31/2017, 1:59 AM@file:JsModule("firebase-admin")
but not if I manually define require
function and request module.
After some investigations I’ve found a problem and the reason is not my code or library.
firebase-admin written in typescript and way how TS defines classes and way how kotlin use them this is the problem.
I could reproduce it on minimal example:
this is a typescript class:
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
Compiled to JS:
var Greeter = /** @class */ (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
};
return Greeter;
}());
So if you use this code in a straitforward way everything is fine:
var greeter = new Greeter("world");
console.log(greeter.greet()); //Hello, world
But Kotlin in generated JS code caches object instance functions to variable and call them using this variable (I think to reduce generated code size). And this is the problem for code above.
You can reproduce such problem in pure JS:
var greeter = new Greeter("world");
var greet = greeter.greet;
console.log(greet); // [Function] -- so greet is function
console.log(greeter.greet()) // Hello, world -- works fine
console.log(greet()); // Hello, undefined -- undefined
So instead of reference to instance function we cached prototype function.
Actually it means that Kotlin JS not compatible with TypeScript and some other pre-ES6 class implementations.
Maybe I missed something, I do not work with JS for a long time and not familiar with TS.
I can build later some more self containing example and create an issue.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
redrield
11/03/2017, 3:30 AMcreate-react-app
with the kotlin flag, and create-react-kotlin-app
.karelpeeters
11/03/2017, 9:09 AMLong
represent? Miliseconds since epoch?bashor
11/03/2017, 5:21 PMDeactivated User
11/04/2017, 12:54 AM/home/travis/build/soywiz/kzlib/kzlib/js/build/node_modules/kzlib-js.js:2169
GZIPInputStream.call($this, in, Inflater_init_3(15 + 16 | 0), size, close_in);
^^
SyntaxError: Unexpected token in
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
...
Fixed here renaming in to i: https://github.com/soywiz/kzlib/commit/a66b8cd319b36237364bcbc26a36f6a54709f963pabl0rg
11/04/2017, 2:56 PMDeactivated User
11/05/2017, 11:44 PMDeactivated User
11/05/2017, 11:45 PMGreg Stepniewski
11/08/2017, 7:09 AM