CLOVIS
02/10/2025, 9:10 PMRobert Jaros
02/10/2025, 9:50 PMCounter
composable function will definitely not compile 😉Tóth István Zoltán
02/11/2025, 3:18 AMvar value by mutableStateOf(0)
val isEven by derivedStateOf { value % 2 === 0 }
Because I like to write this (actual, working, reactive code):
var value = 0
val even = (value % 2 == 0)
box {
onClick { value++ }
if (even) {
text("even")
} else {
text("odd")
}
}
I always felt the the idea of Compose is amazing. But the actual technology I have to use is very restrictive, hard to read, missing quite a few features (especially on web).
I feel that being born on Android is a bit too heavy of a legacy.CLOVIS
02/11/2025, 8:08 AMCLOVIS
02/11/2025, 8:09 AMRobert Jaros
02/11/2025, 8:13 AMval
as function parameter 🙂 And onChange
should be (Int) -> Unit
and not () -> Int
. At least my "in memory" compiler says that ... it can be wrong ... 😉CLOVIS
02/11/2025, 8:15 AMRobert Jaros
02/11/2025, 8:16 AMCLOVIS
02/11/2025, 8:17 AMTóth István Zoltán
02/11/2025, 8:33 AMCLOVIS
02/11/2025, 8:39 AMTóth István Zoltán
02/11/2025, 8:40 AMEdoardo Luppi
02/11/2025, 10:29 AMOnPush
strategy. Even with signal inputs and outputs, OnPush
is the preferred strategy to avoid unnecessary change detection cycles on unchanged component trees.
Note that you may use signals in Angular components withoutWhen using, for example to profit from the greatly simplified lifecycle management, but you will access any of the performance benefits then.signals: true
OnPush
- even without signals - this part isn't true anymore.CLOVIS
02/11/2025, 10:33 AMOnPush
does. I've never seen it used in real life. From the docs, it seems to imply change detection happens whenever an input changes or whenever an event is fired, but that's already the default strategy 🤔Edoardo Luppi
02/11/2025, 10:37 AMOnPush
optimizes the change detection cycles by not processing component trees where input values haven't changed since the last run. The default strategy will always do a pass on all trees and re-render their content.Edoardo Luppi
02/11/2025, 10:38 AMCLOVIS
02/11/2025, 10:39 AMEdoardo Luppi
02/11/2025, 10:45 AMexample: string
), the component isn't marked as dirty, so the change detection run spawned by zone.js won't update its presentation.Edoardo Luppi
02/11/2025, 10:46 AMEdoardo Luppi
02/11/2025, 10:49 AMHttpClient
, so that you can subscribe to the result via the AsyncPipe
which will then call CDR.markForCheck()
whenever the value has changed.CLOVIS
02/11/2025, 10:53 AMOnPush
then, if it can't track local state changes.Edoardo Luppi
02/11/2025, 10:57 AM@Input
, or be tracked using observables/signals when using local state in templates.CLOVIS
02/11/2025, 11:00 AMEdoardo Luppi
02/11/2025, 11:02 AMEdoardo Luppi
02/11/2025, 11:05 AMbut then their best practices often go against using that structureThis one specifically is not clear to me. The structure and usability of Angular is based on RxJS, so every use case was studied based on how to better integrate reactivity in templates, without incurring in performance costs.
CLOVIS
02/11/2025, 11:08 AMNot sure what you mean specifically by this• UI code should go in the template • Component state should be either in inputs or in observables ; ◦ inputs are controlled elsewhere ◦ observables should be controlled by services • Binding to an observable should be in the template (to use
| async
)
there's not much else that could be in a component classEdoardo Luppi
02/11/2025, 11:10 AMthere's not much else that could be in a component classYou still have event handlers, for example. But I get what you mean. Although I do like having clear separation between template and TS code (that's the whole argument against React), there are people that choose to use inline templates and inline styles, so that they have a single TS class for everything that is needed.
Edoardo Luppi
02/11/2025, 11:12 AM@ViewChild/ren
, @ContentChild/ren
, @HostBinding
, @HostListener
CLOVIS
02/11/2025, 11:13 AMEdoardo Luppi
02/11/2025, 11:14 AMCLOVIS
02/11/2025, 11:15 AMAlthough I do like having clear separation between template and TS codePersonally I prefer separating between "UI glue" and "component logic", which React/Compose let me do (but don't enforce). With Angular, I often find the component mostly contains trivial getters or setters for the template, and only a few meaningful things
Kashismails
02/12/2025, 11:34 AMVampire
02/12/2025, 11:41 AMCLOVIS
02/12/2025, 1:09 PMVampire
02/12/2025, 2:07 PMCLOVIS
02/12/2025, 2:21 PMVampire
02/12/2025, 2:24 PM