https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
javascript
  • k

    Kevin Luo

    12/02/2021, 4:38 PM
    Hi, I recently updated my kotlin js app to a newer version of kotlin-react, but it seems now that the
    useEffectWithCleanup
    hook has been removed. I still need it to detach and reattach event listeners for my web page i.e.
    useEffectWithCleanup(listOf(dep1)) {
      addEventListener(element...);
    
      return@useEffectWithCleanup removeEventListener(element...);
    }
    is there an alternative with the newest version of the kotlin-react library?
    t
    a
    • 3
    • 4
  • a

    andylamax

    12/04/2021, 7:00 AM
    Hello any one found a solution to using resources from a kotlin/js library???
    e
    r
    +2
    • 5
    • 9
  • p

    Piotr Krzemiński

    12/06/2021, 9:56 AM
    Hi all, is there some robust way to detect from Kotlin/JS logic if Webpack dev server is running? I want to choose between
    RealBackendClient
    and
    MockedBackendClient
    without the necessity to change code when using Webpack dev server. For now I found out that
    webpackHotUpdatefrontend_react
    function (my module is called
    frontend-react
    ) is defined in
    window
    , but it seems hacky. Is there any more elegant way?
    • 1
    • 1
  • g

    Gabriel Duncan

    12/07/2021, 2:15 PM
    hi everyone :android-wave: . I’m curious how you all start a new fullstack kotlin project with react. is there a starter template that is easy to kickoff? i’d like to make it easy to just start a new project with react and have a default application that can then be added to.
    b
    b
    • 3
    • 4
  • g

    Gabriel Duncan

    12/09/2021, 4:40 PM
    Since updating to the IR compiler i’ve noticed that the
    jsBrowserDevelopment
    task now causes two browser reloads. When i save a file: 1. the re-compile step starts BUT at the same time it looks like the websocket for webpack gets a reload signal 2. so, the browser reloads for webpack dev server websocket signal 3. then it reloads AGAIN when the kotlin compiler finishes the
    jsMainClasses
    task Is anyone else seeing this and if so is there a fix?
    r
    l
    • 3
    • 5
  • a

    atsushieno

    12/10/2021, 7:36 AM
    How can I generate a .js file for IR when I specify
    js(BOTH)
    ? ("Can't use
    executable()
    with 'both' compiler type")
    b
    • 2
    • 4
  • e

    ephemient

    12/10/2021, 8:35 AM
    why does
    jsTest
    run
    main()
    ? none of the other targets have this behavior, but with
    // commonMain
    fun main() {
        println("Hello, world!")
    }
    running
    ./gradlew allTests
    prints out
    > Task :jsNodeTest
    Hello, world!
    sample project attached
    b.zip
    • 1
    • 1
  • p

    Piotr Krzemiński

    12/10/2021, 10:49 AM
    I'm facing the same problem that was described in https://kotlinlang.slack.com/archives/C0B8L3U69/p1583764679215200, that is: I cannot run unit tests because my Jenkins says
    [2021-12-10T10:37:29.209Z] > Task :frontend-react:browserTest
    [2021-12-10T10:37:29.209Z] Cannot start ChromeHeadless
    [2021-12-10T10:37:29.209Z] 	[1210/103728.346077:ERROR:<http://zygote_host_impl_linux.cc|zygote_host_impl_linux.cc>(90)] Running as root without --no-sandbox is not supported. See <https://crbug.com/638180>.
    [2021-12-10T10:37:29.209Z] ChromeHeadless stdout:
    [2021-12-10T10:37:29.209Z] ChromeHeadless stderr: [1210/103728.346077:ERROR:<http://zygote_host_impl_linux.cc|zygote_host_impl_linux.cc>(90)] Running as root without --no-sandbox is not supported. See <https://crbug.com/638180>.
    I told Gradle plugin to look into `karma.config.d`:
    testTask {
        useKarma {
            useConfigDirectory("karma.config.d")
        }
    }
    and there I have
    module.exports = function(config) {
        config.set({
            browsers: ['ChromeHeadlessNoSandbox'],
    
            // you can define custom flags
            customLaunchers: {
                ChromeHeadlessNoSandbox: {
                    base: 'ChromeHeadless',
                    flags: ['--no-sandbox']
                }
            }
        })
    }
    but I'm not even sure if this config is picked up. Too bad Kotlin/JS's Gradle plugin does't allow building on top of available configs. E.g. if I could define:
    fun useChromeHeadlessNoSandbox() {
            config.customLaunchers["ChromeHeadlessNoSandbox"] = CustomLauncher("ChromeHeadless").apply {
                flags.add("--no-sandbox")
            }
            useChromeLike("ChromeHeadlessNoSandbox")
        }
    it could work fine and without defining any extra files. Unfortunately,
    config
    is private now
    i
    • 2
    • 8
  • n

    Nikolai Sviridov

    12/10/2021, 5:13 PM
    Hello! Is there a way to extend
    State
    . I want to create function which changes state in different Component classes.
    // external interface as example, but it will not work
    external interface StateWithError: State {
      var error: Throwable?
    }
    
    fun <S : StateWithError> Component<*, S>.someFunction(){
      setState { 
        error = Throwable("Some msg")
      }
    }
    I tried to use
    external interface
    and
    abstract class
    (even with
    @JsName("error")
    ), but always getting name mangling. Is there a way to create such function?
    ✅ 1
    g
    t
    • 3
    • 9
  • n

    Nikolai Sviridov

    12/10/2021, 5:20 PM
    Also I'm trying to create wrapper for such case github link . How to wrap such case?
    <ForceGraph2D
              ...
              nodePointerAreaPaint={(node, color, ctx) => {
                ...
                // this case
                bckgDimensions && ctx.fillRect(node.x - bckgDimensions[0] / 2, node.y - bckgDimensions[1] / 2, ...bckgDimensions);
              }}
            />
    How to wrap
    bckgDimensions && ctx.fillRect(...)
    ?
    bckgDimension
    is array of 2 Numbers.
    t
    • 2
    • 3
  • l

    LeoColman

    12/11/2021, 3:31 PM
    message has been deleted
    • 1
    • 1
  • t

    Tomasz Krakowiak

    12/12/2021, 8:55 AM
    Anyone have dealt with "Cannot run program "/home/gradle/.gradle/nodejs/node-v14.17.0-linux-x64/bin/node" (in directory "/builds/mensapl/skill-matrix/skillmatrix-frontend-ci/skillmatrix-frontend/build/js"): error=2, No such file or directory"?
    t
    d
    • 3
    • 15
  • b

    bod

    12/12/2021, 1:42 PM
    Hello, World! I have made a Chrome plugin using Kotlin/JS a while ago, and I'm in the process of maintaining/adding a feature. My first step was to update the dependencies, and while I'm at it, I've also switched to the
    IR
    compiler - and unfortunately I experience some errors at runtime. Calling some APIs result in "No matching signature" errors
    TypeError: Error in invocation of bookmarks.create(bookmarks.CreateDetails bookmark, optional function callback): No matching signature.
    I know
    IR
    is still beta but wondering if that rings a bell to anyone. (Not sure how easy it would be for me to create a simple repo project)
    👀 2
    • 1
    • 2
  • s

    simon ballantyne

    12/13/2021, 3:41 PM
    I am trying to create a new project to test out Kotlin/JS, but I cant event get a new demo project to build and compile
    g
    • 2
    • 1
  • i

    Irfan

    12/13/2021, 6:38 PM
    I know it’s not related to Kotlin, but can somebody recommend me a nice desktop app for live streaming feeds from webcam and external camera sources. I know there is OBS but i need to launch, configure input url and start streaming from a python or js script.
    :not-kotlin: 5
    v
    • 2
    • 1
  • r

    Rhiad Jaffar

    12/14/2021, 12:47 PM
    Hello all, We have a KMM project which contains web (React) components built using Kotlin (compiled to js using Kolin/JS of course). We created the web app using the ‘New Application’ > ‘Kotlin’ > ‘React Application’ from IntelliJ. All works okay but with every change we make in the web app the build kicks off and takes around 30 seconds to complete before doing a complete page refresh. This of course does not keep state so aside from the build time means we have to re-navigate/recreate the state from scratch manually to dev/test. We have tried many different solutions to get react ‘hot reload’ or react ‘fast refresh’ working using various configurations - quite a few from the discussions in this channel - but have hit a brick wall and nothing we try seems to work (possibly because Kotlin/JS has moved on quite a bit in the past year). Has anyone managed to get either react ‘hot reload’ or react ‘fast refresh’ working (when writing react components in Kotlin) recently using the IR compiler and if so what settings/code did you use please e.g. in webpack and in
    main
    or components in your kotlin code. Many thanks!
    t
    r
    g
    • 4
    • 12
  • r

    Robert Jaros

    12/14/2021, 6:54 PM
    I've upgraded to 1.6.10 and now I have
    kotlin-js-store
    directory in the root dir of my every project. It's probably related to
    KT-34014
    , but shouldn't it be optional?
    ➕ 1
    t
    m
    • 3
    • 6
  • r

    Rob Murdock

    12/14/2021, 9:35 PM
    EDIT: Before using this fix, be aware of the risks - see links in thread for details. passing this along, since I had to dig through things to figure it out for myself - the 1.6.10 kotlin js plugin automatically defaults to “yarn --ignoreScripts=true”, which can break js libraries that depends on install scripts (I ran into this with an image processing library called sharp) You can turn it off again by putting
    yarn.ignoreScripts = false
    in your build.gradle.kts file
    t
    e
    • 3
    • 6
  • t

    Tomasz Krakowiak

    12/15/2021, 6:02 PM
    Anyone has sample how to package and publish to maven node.js script generated by kotlin? To be more precis - for direct execution on node js, not as a library.
    t
    • 2
    • 4
  • a

    andylamax

    12/16/2021, 12:54 AM
    Hello once again, I think I found a compiler bug PROBLEM So, I have a sealed class like so
    package pimonitor.evaluation.businesses
    
    sealed class BusinessesIntent {
        object LoadBusinesses : BusinessesIntent()
        object ShowCreateBusinessForm : BusinessesIntent()
        object ExitDialog : BusinessesIntent()
        data class ShowInviteToShareReportsForm(val monitored: MonitoredBusiness) : BusinessesIntent()
    }
    whose generated .d.ts looks like this
    export namespace pimonitor.evaluation.businesses {
        class BusinessesIntent {
            private constructor();
            readonly LoadBusinesses: {
            } & pimonitor.evaluation.businesses.BusinessesIntent;
            readonly ShowCreateBusinessForm: {
            } & pimonitor.evaluation.businesses.BusinessesIntent;
            readonly ExitDialog: {
            } & pimonitor.evaluation.businesses.BusinessesIntent;
        }
        namespace BusinessesIntent {
            class ShowInviteToShareReportsForm extends pimonitor.evaluation.businesses.BusinessesIntent {
                constructor(monitored: pimonitor.monitored.MonitoredBusiness);
                readonly monitored: pimonitor.monitored.MonitoredBusiness;
            }
        }
    }
    The class has been compiled inside a nested namespace which makes it so easy to use. However the objects which are now readonly members of BusinessIntent can never be used at all. It is impossible to even instance check
    import { SDK } from "path-to-out-published-lib"
    
    const Intent = SDK.pimonitor.pimonitor.evaluation.businesses.BusinessIntent;
    
    const intent : BusinessIntent = getBusinessIntent()
    
    if(intent instaceof Intent.ShowInviteToShareReportsForm) { // works like charm
    
    } 
    
    if (intent instanceof Intent.LoadBusinesses) { // tsc won't even compile
    
    }
    
    cosole.log(intent == intent.LoadBusinesses) // prints false
    console.log(intent) // shows it is an instance of LoadBusinesses, prints: LoadBusinesses_1
    console.log(intent.LoadBusinesses) // prints: undefined
    This whole shenanigan makes using sealed classes with objects unusable from the js/ts side. Expected behaviour
    if (intent instanceof Intent.LoadBusinesses) { // tsc should be able to compile
    
    }
    I am currently on Kotlin 1.5.31, and yes this is a KMP project. Anyone seen this before? Is there a ticket associated with this? if not I will have to create on and would ask you guys to help me up vote it
    👀 1
    e
    • 2
    • 3
  • s

    solonovamax

    12/16/2021, 7:39 PM
    Hello, I'm looking to create a personal website with kotlin serverside using ktor as well as Kotlin/JS. For this, I want to use minimal javascript for the website and instead server nearly entirely js-free webpages. But, there is also some (very minimal) dynamic content on the pages. For this, I'm using pebble templates with ktor, so ktor will process the templates and chuck out the html for the browser to read. This is done server side instead of client side. I want to keep this. Now, the problem I'm facing is this: I would like to also include some kotlin/js in the website, as well as bundle & process some other assets (like my style sheets which use SASS/SCSS, or a bunch of icons/images I want to minify & include) But to do this, I'm currently hard coding a name for the resulting javascript file and doing a bunch of
    require
    calls at the start of the kotlin main function. But, I want to add more assets as well as pages to the website. For this, I don't want to have to keep adding
    require
    calls to the start of my main
    .kt
    file. Instead, I'd like if webpack took my pebble template as input and used that to resolve assets. (But, there are some other assets, eg. icons, which must be processed even if not included in the source) What's the best way to go about this? I've had quite the difficulty in figuring out how I should do it. Also, I'm fine with moving to another templating language, but the templates need to be rendered server side and not by the javascript. I want clients that can't run javascript to be able to view a fully functioning page.
    t
    • 2
    • 1
  • c

    calrissian

    12/17/2021, 3:55 AM
    I am doing a multi-platform project with reactJs on front and Ktor in the back.. There seems to be an receieving data on the reactJs side.. I can hit the server with a rest client (insomnia) and I am getting the expected data but when I try to make a call from
    jsonClient.get(endpoint + "/")
    I am getting a NoTransformationFoundException .. I noticed that the content type is text/html but not sure if that is the cause of the issue.. any help would be appreciated.. also I configured my httpClient like this
    val jsonClient = HttpClient {
      install(JsonFeature) { serializer = KotlinxSerializer() }
      followRedirects = true
    
    }
    • 1
    • 1
  • n

    Nikola Milovic

    12/18/2021, 12:55 PM
    Hey guys, how can I get this to work, I am again getting confused by ReactNode and Elements. I have this attribute on a wrapper ComponentClass
    var renderCustomHeader: (Date, (Int) -> Unit, (Int) -> Unit,
                             () -> Unit, () -> Unit,
                             Boolean,
                             Boolean) -> ReactNode?
    And I use it like so
    attrs.renderCustomHeader = {
                    date,
                    changeYear,
                    changeMonth,
                    decreaseMonth,
                    increaseMonth,
                    prevMonthButtonDisabled,
                    nextMonthButtonDisabled,
                ->
                    div {
                         //other stuff
                     }
    }
    I tried using createElement, but then the
    changeYear, changeMonth
    aren't usable
    Uncaught TypeError: this._$changeMonth is not a function
    t
    • 2
    • 24
  • t

    Tomasz Krakowiak

    12/19/2021, 3:21 AM
    Hello Guys, how do you build you docker images for node.js?
    b
    • 2
    • 44
  • r

    Rescribet

    12/20/2021, 4:15 PM
    Trying to use spread from JS on a Kotlin JS (IR) class object, but it’ll use the mangled fields. Are there any issues/design notes on this?
    @JsExport
    data class Shape(val type: String, val sides: Int)
    const a = new Shape("square", 4)
    const obj = {...a}
    Expected:
    { type: "square", sides: 4 }
    Actual:
    { _type_1: "square", _sides: 4 }
    t
    • 2
    • 2
  • d

    Derek Ellis

    12/20/2021, 8:18 PM
    I'm running into an error when running
    jsBrowserWebpack
    which just says "See log for details", but I don't see any webpack output in the log. Is there some other log to check? I was able to figure out that the error was caused by a webpack config error through other means, but I'm still confused why there was no errors in the log output. Stacktrace:
    Caused by: java.lang.IllegalStateException: Error occurred. See log for details.
    	at org.jetbrains.kotlin.gradle.internal.ExecKt$execWithErrorLogger$1.invoke(exec.kt:83)
    	at org.jetbrains.kotlin.gradle.internal.ExecKt$execWithErrorLogger$1.invoke(exec.kt:76)
    	at org.jetbrains.kotlin.gradle.internal.ProgressKt.operation(progress.kt:21)
    	at org.jetbrains.kotlin.gradle.internal.ProgressKt.operation$default(progress.kt:12)
    	at org.jetbrains.kotlin.gradle.internal.ExecKt.execWithErrorLogger(exec.kt:76)
    	at org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackRunner.execute(KotlinWebpackRunner.kt:31)
    	at org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack.doExecute(KotlinWebpack.kt:287)
    • 1
    • 1
  • r

    Rescribet

    12/21/2021, 3:43 PM
    Is it correct that the IR bundle size is around 4000 lines or am I missing a DCE flag? (
    jsBrowserProductionWebpack
    ) There are 22 lines in the bundle which are actually related to
    Shape
    which on their own just work as expected (47kB vs 600 byte)
    @JsExport
    data class Shape(val type: String, val sides: Int)
    b
    g
    • 3
    • 21
  • n

    Nicolas Lidin

    12/22/2021, 10:33 AM
    Hey guys ! I'm working on kotlin multiplatform with IR js compiler and I wonder some few things about the ability of using kotlin collections in js. I have created a stack-overflow post about it : https://stackoverflow.com/questions/70437501/kotlin-multiplatform-ir-js-how-to-simply-use-kotlinx-collections-from-js-m Hope someone know a bit about this issue ! (We can talk about it here (not necessarily on stack))
    a
    r
    • 3
    • 4
  • e

    ephemient

    12/28/2021, 3:43 AM
    how do you import a NPM package which exports a function, not a module? e.g. the JS looks like
    module.exports = function...
    ✔️ 1
    a
    t
    • 3
    • 3
  • n

    Nikola Milovic

    12/29/2021, 8:50 AM
    How are these kind of imports translated to Kotlin?
    import { Transition } from '@headlessui/react'
    
     <Transition.Child />
    
    OR 
    <motion.div
    As JsName doesn't accept
    .
    , tried some shenanginas with extension functions but cannot get it to work
    b
    a
    +2
    • 5
    • 10
Powered by Linen
Title
n

Nikola Milovic

12/29/2021, 8:50 AM
How are these kind of imports translated to Kotlin?
import { Transition } from '@headlessui/react'

 <Transition.Child />

OR 
<motion.div
As JsName doesn't accept
.
, tried some shenanginas with extension functions but cannot get it to work
b

Big Chungus

12/29/2021, 9:05 AM
@JsModule("@headlessui/react")
external object HeadlessUI {
 class Transition {
    class Child
  }
}

// Usage

HeadlessUI.Transition.Child
Alternatively, to avoid object wrapping
@file:JsModule("@headlessui/react")

class Transition {
  class Child
}

// Usage

Transition.Child
n

Nikola Milovic

12/29/2021, 9:25 AM
@file:JsModule("@headlessui/react")

external class Transition: ComponentClass<TransitionProps> {
    class Child : ComponentClass<TransitionChildProps> {}
}

external interface TransitionProps : Props {
}
Something along these lines? But now I have to implement the Component Class Tried FC<P> instead of ComponentClass but I lose the ability for this kind of syntax
Transition.Child {
        attrs. ... = ...
}
a

andylamax

12/29/2021, 9:30 AM
I would be going for
TransitionChild
syntax instead of
Transition.Child
n

Nikola Milovic

12/29/2021, 9:33 AM
@andylamax how can I achieve that? I don't mind either
a

andylamax

12/29/2021, 9:36 AM
@JsModule("@headlessui/react")
external val Transition : ComponentType<TransitionProps>

val TransitionChild : ComponentType<TransitionChildProps> = Transition.asDynamic().Child
👌 1
t

turansky

12/29/2021, 12:20 PM
@Daniel Rampelt do you have open wrappers for
headlessui
?
d

Daniel Rampelt

01/03/2022, 3:14 PM
No sorry, just have them as part of my project for now
b

Big Chungus

01/03/2022, 3:16 PM
Might still be worth sharing it here for copy/paste at least
d

Daniel Rampelt

01/03/2022, 6:42 PM
https://gist.github.com/drampelt/7856234a2bac6b0b5e337c1fd197d196 Discussed a while back in this thread https://kotlinlang.slack.com/archives/C5ZTZ6ER0/p1637961054032000
👍 1
View count: 3