created event emitter
This commit is contained in:
parent
b74b928b11
commit
1469a896b4
12 changed files with 87 additions and 24 deletions
6
.idea/artifacts/chatrum_js_1_0_SNAPSHOT.xml
Normal file
6
.idea/artifacts/chatrum_js_1_0_SNAPSHOT.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="chatrum-js-1.0-SNAPSHOT">
|
||||
<output-path>$PROJECT_DIR$/build/libs</output-path>
|
||||
<root id="archive" name="chatrum-js-1.0-SNAPSHOT.jar" />
|
||||
</artifact>
|
||||
</component>
|
6
.idea/artifacts/chatrum_jvm_1_0_SNAPSHOT.xml
Normal file
6
.idea/artifacts/chatrum_jvm_1_0_SNAPSHOT.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="chatrum-jvm-1.0-SNAPSHOT">
|
||||
<output-path>$PROJECT_DIR$/build/libs</output-path>
|
||||
<root id="archive" name="chatrum-jvm-1.0-SNAPSHOT.jar" />
|
||||
</artifact>
|
||||
</component>
|
|
@ -1,10 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="" />
|
||||
<option name="gradleJvm" value="temurin-22" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="temurin-22" project-jdk-type="JavaSDK">
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-22" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
1
.yarnrc
Normal file
1
.yarnrc
Normal file
|
@ -0,0 +1 @@
|
|||
npmRegistryServer: "https://repository.thundernetwork.org/repository/npm-central/"
|
|
@ -1,18 +1,52 @@
|
|||
plugins {
|
||||
kotlin("jvm") version "2.0.20"
|
||||
kotlin("multiplatform") version "2.0.20"
|
||||
id("maven-publish")
|
||||
id("signing")
|
||||
}
|
||||
|
||||
group = "org.thundernetwork"
|
||||
group = "org.thundernetwork.chatrum"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repository.thundernetwork.org/repository/maven-central/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
kotlin {
|
||||
jvm {
|
||||
withSourcesJar()
|
||||
}
|
||||
js (IR) {
|
||||
nodejs {}
|
||||
binaries.library()
|
||||
generateTypeScriptDefinitions()
|
||||
useEsModules()
|
||||
|
||||
compilations["main"].packageJson {
|
||||
customField("types", "kotlin/${project.name}.d.ts")
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
}
|
||||
}
|
||||
val jvmMain by getting {
|
||||
dependencies {
|
||||
}
|
||||
}
|
||||
val jsMain by getting {
|
||||
dependencies {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
js {
|
||||
compilations["main"].packageJson {
|
||||
customField("homepage", "https://source.thundernetwork.org/ThunderNetworkRaD/chatrum")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,2 +1,6 @@
|
|||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
|
||||
}
|
||||
|
||||
rootProject.name = "chatrum"
|
||||
|
||||
|
|
17
src/commonMain/kotlin/EventEmitter.kt
Normal file
17
src/commonMain/kotlin/EventEmitter.kt
Normal file
|
@ -0,0 +1,17 @@
|
|||
package org.thundernetwork.chatrum
|
||||
|
||||
class EventEmitter {
|
||||
private val listeners: MutableMap<String, MutableList<(Any) -> Unit>> = mutableMapOf()
|
||||
|
||||
fun on(eventName: String, listener: (Any) -> Unit) {
|
||||
listeners.getOrPut(eventName) { mutableListOf() }.add(listener)
|
||||
}
|
||||
|
||||
fun off(eventName: String, listener: (Any) -> Unit) {
|
||||
listeners[eventName]?.remove(listener)
|
||||
}
|
||||
|
||||
fun emit(eventName: String, data: Any) {
|
||||
listeners[eventName]?.forEach { it(data) }
|
||||
}
|
||||
}
|
2
src/commonMain/kotlin/Main.kt
Normal file
2
src/commonMain/kotlin/Main.kt
Normal file
|
@ -0,0 +1,2 @@
|
|||
package org.thundernetwork.chatrum
|
||||
|
4
src/jsMain/kotlin/Main.kt
Normal file
4
src/jsMain/kotlin/Main.kt
Normal file
|
@ -0,0 +1,4 @@
|
|||
@file:OptIn(ExperimentalJsExport::class)
|
||||
@file:JsExport
|
||||
import kotlin.js.ExperimentalJsExport
|
||||
import kotlin.js.JsExport
|
1
src/jvmMain/kotlin/Main.kt
Normal file
1
src/jvmMain/kotlin/Main.kt
Normal file
|
@ -0,0 +1 @@
|
|||
package org.thundernetwork.chatrum
|
|
@ -1,16 +0,0 @@
|
|||
package org.thundernetwork
|
||||
|
||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
fun main() {
|
||||
val name = "Kotlin"
|
||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
||||
// to see how IntelliJ IDEA suggests fixing it.
|
||||
println("Hello, " + name + "!")
|
||||
|
||||
for (i in 1..5) {
|
||||
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
||||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
|
||||
println("i = $i")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue