-
-
Save saqib-github-commits/5f41f7baa34e457a485fe1eda24b72e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> derivedStateOf(calculation: () -> T): State<T> = DerivedSnapshotState(calculation) | |
//// | |
private class DerivedSnapshotState<T>( | |
private val calculation: () -> T | |
) : StateObject, DerivedState<T> { | |
private var first: ResultRecord<T> = ResultRecord() | |
/// class implementation | |
} | |
// DerivedState<T> interface | |
internal interface DerivedState<T> : State<T> { | |
/** | |
* The value of the derived state retrieved without triggering a notification to read observers. | |
*/ | |
val currentValue: T | |
/** | |
* A list of the dependencies used to produce [value] or [currentValue]. | |
* | |
* The [dependencies] list can be used to determine when a [StateObject] appears in the apply | |
* observer set, if the state could affect value of this derived state. | |
*/ | |
val dependencies: Set<StateObject> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment