Hi, I have just updated to the latest wrappers and...
# javascript
i
Hi, I have just updated to the latest wrappers and I can't understand how to use
LoaderFunction
now. Lambdas are no longer compatible with the type. E.g. this used to work:
loader = { scope.promise { fetchX() } }
but now it doesn't compile because
Type mismatch: inferred type is () -> Promise<List<WebNativeServerInfo>> but LoaderFunction<Any?>? was expected
I don't see anything in changelog
And I do not understand how to possibly create an instance
What I see in MUI showcase is
Copy code
private val PageLoader: LoaderFunction<Any?> = {
    resolve(MATERIAL_SHOWCASES)
}.unsafeCast<LoaderFunction<Any?>>()
This, honestly, feels so wrong I think it's time to switch to TS
Looks like you need to return a PromiseResult and it may infer the lambda to a LoaderFunction.
i
It doesn't even if I create a dummy lambda that returns PromiseResult
But even if it did, it's still wrong, as it should handle a promise
g
Yeah from this it looks like it should be returning a Promise, not sure why they changed it. In the meantime you can cast your loader function returning a Promise to dynamic. Prob a good idea to open a youtrack ticket also.
👌 1
t
@Ilya P modern Promise was introduced here. To fix problem, which you described we added: 1. Missed
promise
extension for
CoroutineScope
- it returns required Promise 2. Adapter for
LoaderFunction
Changes will be available in next release
pre.732
(probably today)
> Prob a good idea to open a youtrack ticket also. It's definitely good idea to report issue if you have problems like this. If you can't solve problem without
asDynamic
,
unsafeCast
- please report issue.
👌 1
pre.732
released 🎉
h
I updated and now the
LoaderFunction
adapter is not there anymore and I get the error
Interface LoaderFunction does not have constructors
t
LoaderFunction
factory is here. It's signature was changed by authors. Probably you missed second parameter
h
Thank you for your quick reply. I can't really figure it out, for brevity a short loader that had some use before, but is now unused (other Loader have the same issue though):
Copy code
val deviceLoader = LoaderFunction<Any?> { args, context ->
    PromiseResult(Unit)
}
Following the
LoaderFunction
reference leads me to:
Copy code
typealias LoaderFunction<Context> = (args: LoaderFunctionArgs<Context>) -> Any? /* Promise<DataFunctionValue> | DataFunctionValue */
t
Looks like outdated indices 😞
h
I think we already used that factory, because we updated from pre690 to pre754
Oh, so invalidating caches and gradle clean should fix it?
t
"Refresh" in Gradle toolbox will do the job
h
Thank you very much
t
Left button
h
What a silly error. Yes it just didn't occur to me to do a gradle refresh. I just clean and build it.