|
| 1 | +/* |
| 2 | + * Designed and developed by 2025 skydoves (Jaewoong Eum) |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.skydoves.compose.stability.runtime |
| 17 | + |
| 18 | +/** |
| 19 | + * WebAssembly JavaScript implementation of DefaultRecompositionLogger that uses println. |
| 20 | + * |
| 21 | + * Example output: |
| 22 | + * ``` |
| 23 | + * [Recomposition #3] UserProfile (tag: user-screen) |
| 24 | + * ├─ user: User changed (User@abc123 → User@def456) |
| 25 | + * ├─ count: Int stable (42) |
| 26 | + * ├─ onClick: () -> Unit stable |
| 27 | + * └─ Unstable parameters: [user] |
| 28 | + * ``` |
| 29 | + */ |
| 30 | +public actual class DefaultRecompositionLogger : RecompositionLogger { |
| 31 | + public actual constructor() |
| 32 | + |
| 33 | + actual override fun log(event: RecompositionEvent) { |
| 34 | + val tagSuffix = if (event.tag.isNotEmpty()) " (tag: ${event.tag})" else "" |
| 35 | + |
| 36 | + println("[Recomposition #${event.recompositionCount}] ${event.composableName}$tagSuffix") |
| 37 | + |
| 38 | + // Log parameter changes |
| 39 | + event.parameterChanges.forEachIndexed { index, change -> |
| 40 | + val isLast = index == event.parameterChanges.size - 1 |
| 41 | + val prefix = if (isLast) " └─" else " ├─" |
| 42 | + |
| 43 | + val status = when { |
| 44 | + change.changed -> { |
| 45 | + val oldStr = change.oldValue?.toString() ?: "null" |
| 46 | + val newStr = change.newValue?.toString() ?: "null" |
| 47 | + "changed ($oldStr → $newStr)" |
| 48 | + } |
| 49 | + |
| 50 | + change.stable -> "stable (${change.newValue})" |
| 51 | + else -> "unstable (${change.newValue})" |
| 52 | + } |
| 53 | + |
| 54 | + println("$prefix ${change.name}: ${change.type} $status") |
| 55 | + } |
| 56 | + |
| 57 | + // Log unstable parameters summary |
| 58 | + if (event.unstableParameters.isNotEmpty()) { |
| 59 | + println(" └─ Unstable parameters: ${event.unstableParameters}") |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments