Starwave Starwave - 17 days ago 6
TypeScript Question

Code fragment from java to typescript

Don't understand how to structurize this java code to work in typescript(javascript):

channel.join().receive("ok", new IMessageCallback() {
@Override
public void onMessage(Envelope envelope) {
System.out.println("JOINED with " + envelope.toString());
}
});


Code found here: https://github.com/eoinsha/JavaPhoenixChannels

Was thinking about something like this:

var phoenix = (org as any).phoenixframework.channels;
var callback = new phoenix.IMessageCallback({
onMessage: function (arg) {
console.log('callback');
}
});

channel.join().receive("ok", callback);


It compiles successfully and no errors are thrown, but I don't get my callback when I join the channel.

Any insights appreciated!

-- UPDATE
Turns out I was doing it correctly, problem in connection lied elsewhere, thanks all who pitched in! :)

Answer

If you want to implement a Java interface you can use the following syntax.

var clickListener = android.view.View.OnClickListener({
    onClick: function (view) {
        // Do something on click
    }
});

You can refer to the documentation article about android runtime and the data conversion techniques