@@ -29,12 +29,24 @@ import kotlinx.coroutines.cancel
2929import kotlinx.coroutines.launch
3030
3131/* *
32- * Composable that triggers haptic pattern execution when keys change.
32+ * Composable that compiles the haptic pattern in [content] and plays it when [ keys] change.
3333 *
34- * This works similarly to [LaunchedEffect] - when any of the keys change,
35- * the haptic pattern defined in [content] is compiled and executed.
34+ * Like [LaunchedEffect], a change to any key restarts the effect: the pattern is recompiled and
35+ * played. The reactive behavior follows three rules.
36+ *
37+ * 1. Values read inside [content] are frozen at compile time. The pattern is compiled once per key
38+ * change through a single-shot composition that never recomposes (see [compilePattern]), so a
39+ * state value the block captures is read once and does not update on its own.
40+ * 2. Keys are the playback trigger. Put a value in [keys] exactly when its change should fire
41+ * playback. A slider value passed as a key fires on every drag step; state that only shapes the
42+ * pattern belongs inside [content] as a parameter.
43+ * 3. Cancel-and-restart is best effort. A key change cancels the in-flight playback before starting
44+ * the new one, ordered by the manager's state lock. The platform stop calls do not report
45+ * completion, so a few milliseconds of physical overlap are possible.
46+ *
47+ * To make a value both shape the pattern and re-fire when it changes, pass it as a key and read it
48+ * inside the block:
3649 *
37- * Example:
3850 * ```
3951 * var count by remember { mutableStateOf(0) }
4052 *
@@ -48,6 +60,13 @@ import kotlinx.coroutines.launch
4860 * }
4961 * ```
5062 *
63+ * To embed a prebuilt pattern and re-fire when it changes, thread it through the keys and place it
64+ * with [io.github.compose.jindong.dsl.Clip]:
65+ *
66+ * ```
67+ * Jindong(pattern) { Clip(pattern) }
68+ * ```
69+ *
5170 * @param keys Keys that trigger re-execution when changed (like [LaunchedEffect])
5271 * @param content DSL block defining the haptic pattern
5372 */
0 commit comments