Skip to content

Commit 9f843e5

Browse files
committed
📝: add comments
1 parent d082610 commit 9f843e5

7 files changed

Lines changed: 68 additions & 8 deletions

File tree

hooks/src/commonMain/kotlin/xyz/junerver/compose/hooks/declare.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fun <TData : Any> rememberRequest(
4242

4343
//region useAsync
4444
@Composable
45-
fun rememberAsync(fn: SuspendAsyncFn) = useAsync(fn)
45+
fun rememberAsync(block: SuspendAsyncFn) = useAsync(block)
4646

4747
@Composable
4848
fun rememberAsync(): AsyncRunFn = useAsync()
@@ -133,7 +133,7 @@ fun <K, V> rememberMap(pairs: Iterable<Pair<K, V>>) = useMap(pairs)
133133
//endregion
134134

135135
@Composable
136-
fun rememberMount(fn: SuspendAsyncFn) = useMount(fn)
136+
fun rememberMount(block: SuspendAsyncFn) = useMount(block)
137137

138138
@Composable
139139
fun rememberNow(optionsOf: UseNowOptions.() -> Unit = {}) = useNow(optionsOf)

hooks/src/commonMain/kotlin/xyz/junerver/compose/hooks/useAsync.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import kotlinx.coroutines.launch
2020
* async()
2121
* ```
2222
*
23-
* @param fn
23+
* @param block
2424
* @return
2525
* @receiver
2626
*/
2727
@Composable
28-
fun useAsync(fn: SuspendAsyncFn): () -> Unit {
29-
val latestFn by useLatestState(value = fn)
28+
fun useAsync(block: SuspendAsyncFn): () -> Unit {
29+
val latestFn by useLatestState(value = block)
3030
val asyncRunFn = useAsync()
3131
return fun () {
3232
asyncRunFn {

hooks/src/commonMain/kotlin/xyz/junerver/compose/hooks/useAutoReset.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ import kotlinx.coroutines.delay
1313
Version: v1.0
1414
*/
1515

16+
/**
17+
* A composable function that automatically resets a state value to its default
18+
* value after a specified duration (interval).
19+
*
20+
* This function can be used to reset a value back to its default state after a given
21+
* time period has passed, making it useful for situations where you want to restore
22+
* the state to its initial condition after a certain amount of time.
23+
*
24+
* @param default The default value of type `T` that the state will reset to.
25+
* @param interval The `Duration` indicating the time period after which the state
26+
* will be reset to the `default` value.
27+
*
28+
* @return A `MutableState<T>` that holds the current state value, which will be
29+
* automatically reset to `default` after the specified interval.
30+
*
31+
* Example usage:
32+
* ```kotlin
33+
* var autoResetState by useAutoReset(0, 5.seconds)
34+
* autoResetState = 1
35+
* ```
36+
*/
1637
@Composable
1738
fun <T> useAutoReset(default: T & Any, interval: Duration): MutableState<T & Any> {
1839
val state = useState(default = default)

hooks/src/commonMain/kotlin/xyz/junerver/compose/hooks/useBackFront.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ fun useBackToFrontEffect(vararg deps: Any?, effect: () -> Unit) {
4444
* @param effect
4545
* @receiver
4646
*/
47-
4847
@Composable
4948
fun useFrontToBackEffect(vararg deps: Any?, effect: () -> Unit) {
5049
var inBackgroundRef by useRef(default = false)

hooks/src/commonMain/kotlin/xyz/junerver/compose/hooks/useBoolean.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@ import androidx.compose.runtime.remember
1313
Version: v1.0
1414
*/
1515

16+
/**
17+
* A composable function that provides a state holder for a boolean value
18+
* with various utility functions to manipulate the state.
19+
*
20+
* This function allows you to easily manage a boolean state with operations
21+
* like toggling, setting it to `true`, or setting it to `false`. It is useful
22+
* for scenarios where you need to track and manipulate a boolean state in a
23+
* composable function.
24+
*
25+
* @param default The default boolean value for the state. Default is `false`.
26+
*
27+
* @return A [BooleanHolder] object that contains:
28+
* - `state`: The current boolean state value.
29+
* - `toggle`: A function that toggles the state between `true` and `false`.
30+
* - `setValue`: A function to set the state to a specified boolean value.
31+
* - `setTrue`: A function to set the state to `true`.
32+
* - `setFalse`: A function to set the state to `false`.
33+
*
34+
* Example usage:
35+
* ```kotlin
36+
* val (booleanState, toggle) = useBoolean(true)
37+
* toggle() // Will change the state to false.
38+
* ```
39+
*/
1640
@Composable
1741
fun useBoolean(default: Boolean = false): BooleanHolder {
1842
val (state, setState, getState) = useGetState(default)

hooks/src/commonMain/kotlin/xyz/junerver/compose/hooks/useClipboard.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@ import androidx.compose.ui.platform.LocalClipboardManager
77
import androidx.compose.ui.text.AnnotatedString
88

99
/**
10-
* 快捷的使用剪切板:复制、粘贴
10+
* A composable function that provides access to clipboard operations
11+
* like copying and pasting text using the system clipboard manager.
12+
*
13+
* This function allows you to interact with the device's clipboard. You can
14+
* easily copy text to the clipboard or retrieve the text from the clipboard
15+
* using this helper function.
16+
*
17+
* @return A `CopyPasteHolder` object that contains:
18+
* - `copy`: A function that copies the provided text to the clipboard.
19+
* - `paste`: A function that retrieves the text from the clipboard.
20+
*
21+
* Example usage:
22+
* ```kotlin
23+
* val (copy, paste) = useClipboard()
24+
* copy("Hello, world!") // Copies "Hello, world!" to the clipboard.
25+
* val pastedText = paste() // Retrieves text from the clipboard.
26+
* ```
1127
*/
1228
@Composable
1329
fun useClipboard(): CopyPasteHolder {

hooks/src/commonMain/kotlin/xyz/junerver/compose/hooks/useMount.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ import androidx.compose.runtime.Composable
1111
*/
1212

1313
@Composable
14-
fun useMount(fn: SuspendAsyncFn) = useEffect(Unit) { fn() }
14+
fun useMount(block: SuspendAsyncFn) = useEffect(Unit) { block() }

0 commit comments

Comments
 (0)