https://kotlinlang.org logo
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
  • l

    Lawik

    04/24/2019, 11:33 AM
    (Sorry for the late reply) This is what I would like to achieve (I use props/state/class components but it should be the same):
    -.kt
    :tnx: 2
    r
    • 2
    • 12
  • t

    turansky

    04/25/2019, 10:05 AM
    Is there any possibility declare
    AbstractTester
    in Kotlin (without js)?
    -.kt
    b
    • 2
    • 4
  • p

    pabl0rg

    04/25/2019, 7:31 PM
    This also exists: https://github.com/Kabbura/Kunafa
    s
    t
    • 3
    • 7
  • s

    spand

    04/26/2019, 9:15 AM
    Quite often when I have a continuous gradle build running in a terminal, then build in IDEA starts to fail with this exception. Only a full IDEA "Rebuild project" will fix the problem. Am I the only one with this problem ?
    Error:Kotlin: [Internal Error] kotlin.KotlinNullPointerException
    	at org.jetbrains.kotlin.incremental.TranslationResultMap.remove(IncrementalJsCache.kt:166)
    	at org.jetbrains.kotlin.incremental.IncrementalJsCache.clearCacheForRemovedClasses(IncrementalJsCache.kt:107)
    	at org.jetbrains.kotlin.jps.targets.KotlinJsModuleBuildTarget.updateCaches(KotlinJsModuleBuildTarget.kt:228)
    	at org.jetbrains.kotlin.jps.build.KotlinBuilder.doBuild(KotlinBuilder.kt:464)
    	at org.jetbrains.kotlin.jps.build.KotlinBuilder.build(KotlinBuilder.kt:295)
    ... more
    r
    • 2
    • 4
  • a

    Alexander Weickmann

    04/29/2019, 4:35 PM
    Hey all, I am trying to integrate Atlaskit React components into a Kotlin Fullstack application. Unfortunately, I cannot get this working, would appreciate any help. I am starting with this component, because it is the simplest in terms of props: Overview: https://atlaskit.atlassian.com/packages/core/blanket Code: https://bitbucket.org/atlassian/atlaskit-mk-2/src/master/packages/core/blanket/src/Blanket.tsx Compiled JS:
    import * as tslib_1 from "tslib";
    import * as React from 'react';
    import { withAnalyticsEvents, withAnalyticsContext, createAndFireEvent, } from '@atlaskit/analytics-next';
    import { name as packageName, version as packageVersion } from './version.json';
    import Div from './styled';
    var Blanket = /** @class */ (function (_super) {
        tslib_1.__extends(Blanket, _super);
        function Blanket() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        Blanket.prototype.render = function () {
            var _a = this.props, canClickThrough = _a.canClickThrough, isTinted = _a.isTinted, onBlanketClicked = _a.onBlanketClicked;
            var onClick = canClickThrough ? null : onBlanketClicked;
            var containerProps = { canClickThrough: canClickThrough, isTinted: isTinted, onClick: onClick };
            return React.createElement(Div, tslib_1.__assign({}, containerProps));
        };
        Blanket.defaultProps = {
            canClickThrough: false,
            isTinted: false,
            onBlanketClicked: function () { },
        };
        return Blanket;
    }(React.Component));
    export { Blanket as BlanketWithoutAnalytics };
    var createAndFireEventOnAtlaskit = createAndFireEvent('atlaskit');
    export default withAnalyticsContext({
        componentName: 'blanket',
        packageName: packageName,
        packageVersion: packageVersion,
    })(withAnalyticsEvents({
        onBlanketClicked: createAndFireEventOnAtlaskit({
            action: 'clicked',
            actionSubject: 'blanket',
            attributes: {
                componentName: 'blanket',
                packageName: packageName,
                packageVersion: packageVersion,
            },
        }),
    })(Blanket));
    //# sourceMappingURL=Blanket.js.map
    My binding:
    @file:JsModule("@atlaskit/blanket")
    
    package atlaskit
    
    import org.w3c.dom.events.Event
    import react.*
    
    external class Blanket : Component<BlanketProps, RState> {
        override fun render()
    }
    
    external interface BlanketProps : RProps {
        var canClickThrough: Boolean
        var isTinted: Boolean
        var onBlanketClicked: (Event) -> Unit
    }
    Creation:
    child(Blanket::class) {
                        attrs.isTinted = true
                        attrs.canClickThrough = true
                        attrs.onBlanketClicked = {}
                    }
    This prints following error to the console: "Uncaught (in promise) TypeError: Cannot read property '$metadata$' of undefined" Any tips on what I am doing wrong?
    • 1
    • 1
  • s

    sdeleuze

    05/02/2019, 9:41 AM
    @bashor Any chance you could consider supporting officially Web Component via a Kotlin equivalent of https://www.polymer-project.org/blog/2019-02-05-lit-element-and-lit-html-release in Kotlin/JS (it could require fixing https://youtrack.jetbrains.com/issue/KT-24882 as hinted by @jdemeulenaere) in order to provide an attractive way to do frontend with Kotlin without requiring a full rewrite of Angular/Vue/React?
    👀 1
    b
    • 2
    • 1
  • n

    Nikky

    05/06/2019, 6:37 PM
    i may need help with using uglify.js on what dce spits out i am getting this error:
    Parse error at build/kotlin-js-min/client-js/main/d2v-chord-js.js.map:1,10
    {"version":3,"file":"d2v-chord-js.js","sources":["../../../../../d2v-chord-commo
              ^
    ERROR: Unexpected token: punc «:», expected: punc «;»
        at JS_Parse_Error.get (eval at <anonymous> (/usr/lib/node_modules/uglify-js/tools/node.js:20:1), <anonymous>:71:23)
        at fatal (/usr/lib/node_modules/uglify-js/bin/uglifyjs:296:53)
        at run (/usr/lib/node_modules/uglify-js/bin/uglifyjs:240:9)
        at Object.<anonymous> (/usr/lib/node_modules/uglify-js/bin/uglifyjs:165:5)
        at Module._compile (internal/modules/cjs/loader.js:701:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
        at Module.load (internal/modules/cjs/loader.js:600:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
        at Function.Module._load (internal/modules/cjs/loader.js:531:3)
        at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    an i am not sure if thats a well known error or if i am calling uglifyjs completely wrong
    g
    • 2
    • 7
  • t

    thana

    05/07/2019, 7:45 AM
    im receiving an object from "real" js code which has all the properties like a data class i defined, but is not an instance of that class. is there an easy way to convert it into an object of my class in that case?
    r
    a
    • 3
    • 4
  • j

    Joffrey

    05/07/2019, 1:49 PM
    Anyone here has experience with Gradle kotlin-frontend-plugin? I'm wondering whether npm dependencies with typescript definitions are directly usable from Kotlin without manual declaration of
    external
    declarations. I guess I could generate Kotlin externals using ts2kt, but is it done out-of-the box by the plugin?
    l
    t
    • 3
    • 12
  • n

    nulldev

    05/09/2019, 5:21 PM
    What's this new dukat thing? https://github.com/Kotlin/dukat Does anybody know how it compares to ts2kt?
    👀 3
    t
    u
    • 3
    • 3
  • j

    jacob

    05/13/2019, 7:44 AM
    @Lawik I haven't tried this yet, but can you use the raw javascript to write the require statement?
    l
    • 2
    • 1
  • s

    Sergio Casero

    05/13/2019, 9:17 AM
    Hello guys, I'm facing this rare issue:
    ERROR in ../node_modules_imported/kotlin-extensions/kotlin-extensions.js
    Module not found: Error: Can't resolve 'core-js/features/object/assign' in '/home/sergio/projects/timesheet/js/build/node_modules_imported/kotlin-extensions'
     @ ../node_modules_imported/kotlin-extensions/kotlin-extensions.js 112:37-78
     @ ../node_modules_imported/kotlin-react-dom/kotlin-react-dom.js
     @ ./output.js
    Any help? It's rare because I have another project with exactly the same structure and works fine I'll paste the build.gradle file on the thread
    l
    r
    n
    • 4
    • 11
  • s

    Sergio Casero

    05/13/2019, 10:55 AM
    Could I call firebase from kotlin?
    j
    b
    • 3
    • 3
  • l

    Lawik

    05/14/2019, 6:53 AM
    How can I load assets (png, svg, etc) when using the
    kotlin-frontend
    plugin? Preferably from the
    resources
    folder.
    n
    a
    • 3
    • 13
  • a

    Alexander Weickmann

    05/15/2019, 11:37 AM
    Kotlin react wrapper says "Major version number of this wrapper matches that of React itself." Unfortunately, only 16 is available: https://bintray.com/kotlin/kotlin-js-wrappers/kotlin-react Is an 16.8.x in the works?
    l
    • 2
    • 4
  • t

    thana

    05/15/2019, 12:41 PM
    how would i create objects of an `external`ly defined classes?
    d
    • 2
    • 3
  • j

    janvladimirmostert

    05/16/2019, 8:37 AM
    What are the main problems that Angular, ReactJS and VueJS solve? As i understand it, all three of them have a change detection mechanism that can figure out when data changes and then a mechanism to figure out which parts of the DOM to update. Is there a whitepaper somewhere explaining what algorithms they use for change detection and what they use to figure out which parts of the DOM needs updating? Curious about how much work it would be to build a pure KotlinJS framework that runs on top of kotlinx.html
    👍 1
    r
    g
    s
    • 4
    • 30
  • s

    spand

    05/16/2019, 9:04 AM
    I see this pattern a lot but I cant really figure out how to do the same from KotlinJS. Ie. how can I define a class and then export it in a decorated fashion?
    class MyComponent extends React.Component {
      render () {
        return <div className={this.props.classes.root} />;
      }
    }
    
    export default withStyles(styles)(MyComponent);
    g
    • 2
    • 22
  • h

    hallvard

    05/16/2019, 9:27 AM
    I am about to build a webpack for myself from a project that is an MPP. In older examples, I find gradle stuff like 'kotlinFrontend { webpackBundle { ... } }'. Would anyone know how to get a webpack of my javascripts from an mpp (or is this question better suited for #multiplatform maybe?)
    r
    • 2
    • 2
  • u

    U75957

    05/18/2019, 6:03 AM
    If we try to implement interface, it produce generating
    getter/setters
    via
    Object.defineProperty
    . For example:
    external interface IModel {
        val id: Int
        var name: String
    }
    
    class CModel (
        override val id: Int,
        override var name: String
    ) : IModel
    will transpilled to:
    function CModel(id, name) {
        this.id_4s8xc9$_0 = id;
        this.name_j0rqo7$_0 = name;
      }
      Object.defineProperty(CModel.prototype, 'id', {
        get: function () {
          return this.id_4s8xc9$_0;
        }
      });
      Object.defineProperty(CModel.prototype, 'name', {
        get: function () {
          return this.name_j0rqo7$_0;
        },
        set: function (name) {
          this.name_j0rqo7$_0 = name;
        }
      });
    How to avoid generating
    getter/setter
    ? I need to interact with JS/TS libs. And such libs see only mangled fields, because properties defined via
    Object.defineProperty
    not accessible by
    Object.getOwnPropertyNames()
    . Using
    external interface
    and
    @JsName()
    don't help. If we define
    class
    , which does not implement any
    interface
    such
    getter/setters
    will not be generated. I also noticed that such
    getter/setters
    are generated only for properties which have
    override
    g
    • 2
    • 2
  • i

    Ilya Goncharov [JB]

    05/20/2019, 10:33 AM
    Hello, kotlin-frontend-plugin generates package.json with 'kotlin' dependency If Kotlin/JS is used for distibuting js library (kotlin is bundled) and consumers depend on this library, they should install 'kotlin' dependency. But why is it necessary, if it was bundled? And where can they take 'kotlin' dependency from?
    • 1
    • 1
  • r

    robnik

    05/21/2019, 8:10 AM
    Is this
    kotlin-dce-js
    plugin (https://kotlinlang.org/docs/reference/javascript-dce.html) still the thing to use, or is this frontend plugin replacing it? https://github.com/Kotlin/kotlin-frontend-plugin
    a
    r
    • 3
    • 3
  • r

    Robert Jaros

    05/24/2019, 2:37 PM
    Anyone knows an implementation of
    Result<V, E : Exception>
    (similar to: https://github.com/kittinunf/Result) with support for Kotlin/JS?
    g
    • 2
    • 1
  • e

    eygraber

    05/24/2019, 7:12 PM
    I'm trying to get kotlinjs to work with Firebase cloud functions, but I'm running into an issue when I build my project. The structure of the project calls for a directory called
    /functions
    that contains
    index.js
    ,
    node_modules
    ,
    package.json
    and
    package-lock.json
    . My source is in
    /src/main/kotlin
    . Every time I build,
    index.js
    is correctly put into
    /functions
    but the other files are deleted. My
    build.gradle
    file is below. Any one have any advice?
    plugins {
        id 'kotlin2js' version '1.3.31'
    }
    
    group 'com.myapp'
    version '1.0.0'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-js"
        testImplementation "org.jetbrains.kotlin:kotlin-test-js"
    }
    
    compileKotlin2Js.kotlinOptions {
        moduleKind = "commonjs"
        outputFile = "functions/index.js"
        sourceMap = true
    }
    g
    • 2
    • 1
  • e

    eygraber

    05/24/2019, 7:25 PM
    More context: if I "build" using Intellij this happens. If I run
    ./gradlew build
    it does not.
    g
    • 2
    • 1
  • f

    fcosta

    05/25/2019, 4:37 PM
    Hey guys! I'm getting an error when trying to call a function created with Koltin and coroutines from javascript. It's a very simple call:
    applicationApi.fetchCharacters(function (result) {
        console.log(result)
    })
    And the error:
    IllegalStateException: No more continuations to resume
    Any suggestion on what it's going on?
    b
    • 2
    • 2
  • d

    Dima Avdeev

    05/26/2019, 6:29 AM
    I see a lot of work in the Gradle plugin https://github.com/JetBrains/kotlin/tree/master/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js. There are npm and webpack. When can this be expected in the release? Does this mean that https://github.com/Kotlin/kotlin-frontend-plugin becomes obsolete?
    i
    t
    b
    • 4
    • 3
  • r

    Rohan Maity

    05/26/2019, 11:29 AM
    How can I access Js Array in Kotlin file ?
    t
    g
    b
    • 4
    • 9
  • s

    Slackbot

    05/26/2019, 12:05 PM
    This message was deleted.
    ❌ 2
    b
    t
    • 3
    • 2
  • s

    simon.vergauwen

    05/27/2019, 12:31 PM
    I am not sure what to do for KotlinJS, and how it relates to those 2 functions.
    s
    r
    +2
    • 5
    • 16
Powered by Linen
Title
s

simon.vergauwen

05/27/2019, 12:31 PM
I am not sure what to do for KotlinJS, and how it relates to those 2 functions.
s

spand

05/27/2019, 12:50 PM
For js in the browser there are
Date.getTime()
and https://developer.mozilla.org/en-US/docs/Web/API/Performance
Not sure if you need more than that
s

simon.vergauwen

05/27/2019, 12:54 PM
Alright, that also point to that there is no alternative for
getTimeNanos
or
CLOCK_MONOTONIC
in Js.
s

spand

05/27/2019, 1:08 PM
Well, javas is pretty much best effort also:
This method provides nanosecond precision, but not necessarily
     * nanosecond resolution (that is, how frequently the value changes)
     * - no guarantees are made except that the resolution is at least as
     * good as that of {@link #currentTimeMillis()}.
s

simon.vergauwen

05/27/2019, 1:09 PM
Yes, I am aware of that. It depends a lot on the underlying system, which is fine.
I am working on a
Clock
abstraction for Arrow. Some other MPP languages (or frameworks in languages) I checked offer both since
nanos
is better suited for tracking timed events compared to
millis
.
I was wondering if Kotlin had already thought out something for this issue.
r

ribesg

05/27/2019, 1:20 PM
Jetbrains is working on a mpp date-time thing iirc
👍 3
s

simon.vergauwen

05/27/2019, 1:21 PM
Ah awesome thanks! Any references would be appreciate, can’t seem to find anything
r

ribesg

05/27/2019, 1:33 PM
Last time I heard about it it was more of a plan I think, I’m not sure. There were also talks about a mpp file lib
f

fcosta

05/27/2019, 2:44 PM
You can use this library for mpp projects: https://github.com/korlibs/klock
r

ribesg

05/27/2019, 2:50 PM
That works but I don’t like its API
s

simon.vergauwen

05/27/2019, 2:54 PM
Thanks for the reference @fcosta. I'll check the sources of that repo :)
b

bashor

05/27/2019, 8:02 PM
in Kotlin/JS you can write something like
js("Date").now()
or
window.performance.now()
for
window
you need
import kotlin.browser.window
s

simon.vergauwen

05/27/2019, 8:34 PM
@bashor awesome! thanks for the response
View count: 3