Skip to content

Instantly share code, notes, and snippets.

View lelandrichardson's full-sized avatar

Leland Richardson lelandrichardson

View GitHub Profile
@lelandrichardson
lelandrichardson / Recoil.kt
Created August 28, 2020 14:52
Recoil vs Compose
var text by mutableStateOf("")
val charCount: Int get() = text.length
val todoList = mutableStateListOf<Item>(emptyList())
val filteredTodoList get() = when (todoListFilter) {
Filter.Completed -> todoList.filter { it.isComplete }
Filter.Uncompleted -> todoList.filter { !it.isComplete }
Filter.All -> todoList
}
@Composable fun Example() {
$composer.end()?.updateScope { nextComposer ->
Counter(nextComposer)
}
fun Counter($composer: Composer) {
$composer.start(123)
var count = remember($composer) { mutableStateOf(0) }
Button(
$composer,
text="Count: ${count.value}",
onPress={ count.value += 1 },
)
$composer.end()
}
fun Google(
$composer: Composer,
number: Int
) {
if (number == $composer.next()) {
Address(
$composer,
number=number,
street="Amphitheatre Pkwy",
city="Mountain View",
fun Address(
$composer: Composer,
$static: Int,
number: Int, street: String,
city: String, state: String, zip: String
) {
Text($composer, ($static and 0b11) and (($static and 0b10) shr 1), "$number $street")
Text($composer, ($static and 0b100) shr 2, city)
Text($composer, 0b1, ", ")
Text($composer, ($static and 0b1000) shr 3, state)
fun Google(
$composer: Composer,
$static: Int,
number: Int
) {
Address(
$composer,
0b11110 or ($static and 0b1),
number=number,
street="Amphitheatre Pkwy",
@Composable fun Google(number: Int) {
Address(
number=number,
street="Amphitheatre Pkwy",
city="Mountain View",
state="CA"
zip="94043"
)
}
@Composable fun App() {
val x = remember { Math.random() }
// ...
}
@Composable
fun <T> remember(vararg inputs: Any?, calculation: () -> T): T
@Composable
fun App(items: List<String>, query: String) {
val results = items.filter { it.matches(query) }
// ...
}