Skip to content

Commit

Permalink
Merge pull request #13 from lightningkite/immediate-write-changes
Browse files Browse the repository at this point in the history
Made LazyProperty and Draft ImmediateWrite
  • Loading branch information
iHoonter authored Oct 24, 2024
2 parents 1cc5193 + 9498f52 commit 58ee76a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.lightningkite.kiteui.reactive
class Draft<T> private constructor(
val published: Writable<T>,
private val draft: LazyProperty<T>
): Writable<T> by draft {
): ReadableWithImmediateWrite<T> by draft {
constructor(published: Writable<T>) : this(published, LazyProperty(stopListeningWhenOverridden = false) { published() })
constructor(initialValue: ReactiveContext.() -> T) : this(
LazyProperty(
Expand All @@ -21,4 +21,7 @@ class Draft<T> private constructor(
return awaitOnce()
}
fun cancel() { draft.reset() }

override suspend fun reportSetException(exception: Exception) { draft.reportSetException(exception) }
override suspend fun set(value: T) { draft.setImmediate(value) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LazyProperty<T>(
private val useLastWhileLoading: Boolean = false,
private val log: Console? = null,
initialValue: ReactiveContext.() -> T
): Writable<T> {
): ReadableWithImmediateWrite<T> {

private val shared = SharedReadable(useLastWhileLoading = useLastWhileLoading, action = initialValue)

Expand Down Expand Up @@ -89,7 +89,7 @@ class LazyProperty<T>(
state = ReadableState(value)
}

override suspend fun set(value: T) { this.value = value }
override fun setImmediate(value: T) { this.value = value }

/**
* Resets the LazyProperty to the initial value calculation.
Expand Down

0 comments on commit 58ee76a

Please sign in to comment.