julien lengrand-lambert
04/01/2022, 1:39 PMimport { doc, onSnapshot } from "firebase/firestore";
const unsub = onSnapshot(doc(db, "cities", "SF"), (doc) => {
console.log("Current data: ", doc.data());
});
This snippet listens to realtime changes in firestore and triggers the callback function then.
I literally have no clear idea how to bind this with my Kotlin. The main issue I see is that I would need to pass a function as input to the binding, with access to the kotlin side data 🧐julien lengrand-lambert
04/01/2022, 2:12 PMjulien lengrand-lambert
04/01/2022, 2:14 PMexport function syncMessages(callback){
listen(() => {
callback()
})
on the kotlin side, call and integrate an anonymous function
@JsModule("@jlengrand/firebase-ports")
@JsNonModule
external object FirebasePorts{
fun syncMessages(callback: () -> Unit)
}
FirebasePorts.syncMessages() { -> println("BOUM") }
julien lengrand-lambert
04/01/2022, 2:15 PMlisten
will be called, so will callback
. Haven't tried yet but pretty sure that works with parameters and promises as wellDerek Ellis
04/01/2022, 2:28 PMlisten()
directly from Kotlin and pass it the lambda?julien lengrand-lambert
04/01/2022, 2:31 PMjulien lengrand-lambert
04/01/2022, 2:32 PMjulien lengrand-lambert
04/01/2022, 2:32 PM