Skip to content

Instantly share code, notes, and snippets.

@saqib-github-commits
Last active May 31, 2023 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saqib-github-commits/5f41f7baa34e457a485fe1eda24b72e4 to your computer and use it in GitHub Desktop.
Save saqib-github-commits/5f41f7baa34e457a485fe1eda24b72e4 to your computer and use it in GitHub Desktop.
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