Best practices for packages

tl/dr; First real project with kotlin, wondering for best practices for code organization.

Hi there, I’m working on my first Kotlin project (coming from Java).

The system is pretty basic, right now all I have is a couple of data classes (value objects) with the corresponding repositories.

For those I have two files, model.kt and repositories.kt.

Back in Java (with the one file one class rule) I would make a model package and a persistence package. Trying to keep that sense of order I have made the packages, but there’s a single file on each with multiple (simple) classes. (Each of those have 20 lines or less).

Right now I feel that the packages (as a directory structure) are not needed, but having all my files on the root directory feels wrong. But, again, I don’t know if that’s just some kind of stockholm syndrome.

Any suggestion will be appreciated.

submitted by /u/d3249
[link] [comments]

Continue Reading Best practices for packages

Having worked with kotlin sealed classes for some time now, I feel that the Java 15 version of sealed classes are more flexible and allows better readability with the offence of being verbose on the declaration. Which one will you prefer?

submitted by /u/s_a_u_r_a_b_h
[link] [comments]

Continue Reading Having worked with kotlin sealed classes for some time now, I feel that the Java 15 version of sealed classes are more flexible and allows better readability with the offence of being verbose on the declaration. Which one will you prefer?

[P] ML With Android 11

Hey,

I open-sourced this repo by me demonstrating how you can get started with Machine Learning in Android 11 with Kotlin, all that is new. I further even explain how the code works so you can very easily get started with implementing Machine Learning in your Android apps with cool examples!

(PS: Leave me a star if this looks good to you, helps me a lot.)

https://github.com/Rishit-dagli/ML-with-Android-11

submitted by /u/Rishit-dagli
[link] [comments]

Continue Reading [P] ML With Android 11

How to set up Kotlin for NodeJS with TS dependencies?

Hey, I’ve been using Kotlin in the JVM for a few years and I decided to try it on nodejs (I’m also working with node for a few years, so I’m not newbie in the platform).

โ€‹

I went to IDEA > New Project > Gradle > Kotlin (NodeJS). Added a few dependencies and enable the experimental Dukat:

build.gradle.kts

dependencies {implementation(kotlin("stdlib-js"))implementation(npm("firebase", "7.20.0"))implementation(npm("left-pad", "1.3.0"))}

โ€‹

gradle.properties

kotlin.code.style=officialkotlin.js.experimental.generateKotlinExternals=true

Both firebase and left-pad (obviously I’m using this for test) does have typescript mappings, so the kotlin mappings should be generated, right?

I refreshed Gradle and went to the src/main trying to import the dependencies, but nothing happened and I don’t know why. Looking at build/js/node_modules the dependencies are there.

โ€‹

I tried to run the Dukat gradle tasks and nothing happened too.

โ€‹

This section about external dependencies is very bad documented, I need some help to set it up.

btw I’m on Kotlin 1.4, my full build.gradle looks like this:

plugins {id("org.jetbrains.kotlin.js") version "1.4.10"}group = "dev.nathanpb"version = "1.0.0"repositories {mavenCentral()}dependencies {implementation(kotlin("stdlib-js"))implementation(npm("firebase", "7.20.0"))implementation(npm("left-pad", "1.3.0"))}kotlin {js {nodejs {}binaries.executable()}}

โ€‹

Thank you all, hope I will be using this in production soon

โ€‹

SOLUTION: I’m stupid and can’t read documentations: https://kotlinlang.org/docs/reference/js-external-declarations-with-dukat.html#generating-external-declarations-at-build-time

submitted by /u/_nathata
[link] [comments]

Continue Reading How to set up Kotlin for NodeJS with TS dependencies?

Using createPortal in functionalComponent of Kotlin-react

Does anyone have some idea how to use createPortal in kotlin-react for example to render a modal? i have tried several ways and nothing is working. Iยดm new at Kotlin. Here is one way i tryed:

interface Modalprops:RProps{

var visible:Boolean

}

val modal = functionalComponent<Modalprops> {props->

val (container) = useState(document.create.div{+"asdasdsa"})

useEffectWithCleanup(emptyList()) {

document.body?.appendChild(container)

[email protected] { document.body?.removeChild(container)}

}

createPortal(container){

if(props.visible) {

div { +"asdasd" }

}

}

}

fun RBuilder.OModal(isvisible:Boolean, handler:Modalprops.()->Unit) = child(modal){

attrs{

visible=isvisible

}

}

its just how its working in good old TS and i tried to transfer it to kotlin-react but createPortal seems to do nothing in this case.

โ€‹

It would be nice if some could give me an example of how implement this example correct in react-kotlin.

submitted by /u/Jimschi
[link] [comments]

Continue Reading Using createPortal in functionalComponent of Kotlin-react

End of content

No more pages to load