Skip to content

Commit

Permalink
Removed broken base directive
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Nov 21, 2024
1 parent 61faa8c commit fa59ae5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
1 change: 0 additions & 1 deletion example-app/src/jsMain/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<base href="http://localhost:5175/">
<title>JS Client</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="stylesheet" href="/experimental.css" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.lightningkite.kiteui.reactive

import com.lightningkite.kiteui.*
import com.lightningkite.kiteui.utils.commaString
import com.lightningkite.kiteui.views.launch
import kotlinx.coroutines.*
import kotlinx.coroutines.launch
import kotlin.js.JsName
Expand Down Expand Up @@ -355,14 +356,14 @@ fun <T> Readable<Writable<T>>.flatten(): Writable<T> = shared { this@flatten()()
.withWrite { this@flatten.state.onSuccess { s -> s set it } }


interface ReadableEmitter<T> {
interface ReadableEmitter<T>: CoroutineScope {
fun emit(value: T)
}

fun <T> CoroutineScope.readable(emitter: suspend ReadableEmitter<T>.() -> Unit): Readable<T> {
val prop = LateInitProperty<T>()
launch {
emitter(object : ReadableEmitter<T> {
emitter(object : ReadableEmitter<T>, CoroutineScope by this {
override fun emit(value: T) {
prop.value = value
}
Expand All @@ -371,6 +372,43 @@ fun <T> CoroutineScope.readable(emitter: suspend ReadableEmitter<T>.() -> Unit):
return prop
}

fun <T> sharedProcess(scope: CoroutineScope = AppScope, emitter: suspend ReadableEmitter<T>.() -> Unit): Readable<T> {
return object: BaseReadable<T>() {
var job: Job? = null
override fun activate() {
job = scope.launch {
emitter(object : ReadableEmitter<T>, CoroutineScope by this@launch {
override fun emit(value: T) {
state = ReadableState(value)
}
})
}
}
override fun deactivate() {
job?.cancel()
job = null
}
}
}
fun <T> sharedProcessRaw(scope: CoroutineScope = AppScope, emitter: suspend ReadableEmitter<ReadableState<T>>.() -> Unit): Readable<T> {
return object: BaseReadable<T>() {
var job: Job? = null
override fun activate() {
job = scope.launch {
emitter(object : ReadableEmitter<ReadableState<T>>, CoroutineScope by this@launch {
override fun emit(value: ReadableState<T>) {
state = value
}
})
}
}
override fun deactivate() {
job?.cancel()
job = null
}
}
}

fun <T> CoroutineScope.asyncReadable(action: suspend () -> T): Readable<T> {
val prop = LateInitProperty<T>()
launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ actual suspend fun fetch(
onUploadProgress?.let {
onUpload { a, b ->
run {
it(a.toInt(), b.toInt())
it(a.toInt(), b?.toInt() ?: -1)
}
}
}
onDownloadProgress?.let {
onDownload { a, b ->
run {
it(a.toInt(), b.toInt())
it(a.toInt(), b?.toInt() ?: -1)
}
}
}
Expand Down

0 comments on commit fa59ae5

Please sign in to comment.