aballano
11/01/2019, 4:12 PMLuca Nicoletti
11/01/2019, 4:13 PMGiorgos Neokleous
11/01/2019, 4:14 PMLuca Nicoletti
11/01/2019, 4:14 PMaballano
11/01/2019, 4:16 PMLuca Nicoletti
11/01/2019, 4:16 PMaballano
11/01/2019, 4:18 PMLeland Richardson [G]
11/01/2019, 4:23 PMLeland Richardson [G]
11/01/2019, 4:24 PMthemishkun
11/01/2019, 4:24 PMLeland Richardson [G]
11/01/2019, 4:24 PMLeland Richardson [G]
11/01/2019, 4:25 PMLuca Nicoletti
11/01/2019, 4:25 PMLeland Richardson [G]
11/01/2019, 4:25 PMLeland Richardson [G]
11/01/2019, 4:25 PMvar x = +memo { MyModel(...) }Leland Richardson [G]
11/01/2019, 4:25 PMLeland Richardson [G]
11/01/2019, 4:25 PM+state isaballano
11/01/2019, 4:27 PMLeland Richardson [G]
11/01/2019, 4:28 PMval x = +state { 0 } is basically shorthand for val x = +memo { State(0) } where State is a value holder class annotated with @ModelLeland Richardson [G]
11/01/2019, 4:28 PMLeland Richardson [G]
11/01/2019, 4:29 PMMichal Bacik
11/01/2019, 4:47 PMLeland Richardson [G]
11/01/2019, 4:49 PMLeland Richardson [G]
11/01/2019, 4:50 PMLeland Richardson [G]
11/01/2019, 4:50 PMLeland Richardson [G]
11/01/2019, 4:50 PMLuca Nicoletti
11/01/2019, 4:51 PMaballano
11/01/2019, 4:51 PMmemo is what I was missing @Leland Richardson [G] Now it's working with lazy val + setting mutable variables inside the model
val mainModel by lazy { +model { MainModel() } }Leland Richardson [G]
11/01/2019, 4:54 PMLuca Nicoletti
11/01/2019, 4:54 PMLeland Richardson [G]
11/01/2019, 4:54 PMunaryPlus operator is global, and will not work once we take it away (which will be very soon)Leland Richardson [G]
11/01/2019, 4:55 PM+ as something you can only use inside of a composable functionLuca Nicoletti
11/01/2019, 4:55 PMhere in the channel when the + will be removed?Leland Richardson [G]
11/01/2019, 4:55 PMLeland Richardson [G]
11/01/2019, 4:55 PMLuca Nicoletti
11/01/2019, 4:56 PMLeland Richardson [G]
11/01/2019, 4:56 PMLuca Nicoletti
11/01/2019, 4:56 PMaballano
11/01/2019, 4:56 PMaballano
11/01/2019, 5:06 PMLeland Richardson [G]
11/01/2019, 5:09 PMLeland Richardson [G]
11/01/2019, 5:09 PMdata class Message(
val sender: String,
val message: String
)
@Model
data class MainModel(
var messages: List<Message> = emptyList()
)
class MainActivity : AppCompatActivity() {
private val algebra = MainAlgebra()
private val mainModel = MainModel()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
mainContent(mainModel, ::onButtonClicked)
}
}
private fun onButtonClicked() {
algebra.getMessages().continueOn(UIContext).unsafeRunAsync { cb ->
cb.fold(
ifRight = {
mainModel.messages = mainModel.messages + it
},
ifLeft = { throw it }
)
}
}
}Leland Richardson [G]
11/01/2019, 5:09 PMLuca Nicoletti
11/01/2019, 5:10 PMList now working? 🙂 Isn’t ModelList the preferred one?Leland Richardson [G]
11/01/2019, 5:11 PMLeland Richardson [G]
11/01/2019, 5:12 PMdata class Message(
val sender: String,
val message: String
)
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
mainContent()
}
}
}
@Composable fun mainContent() {
val algebra = +memo { MainAlgebra() }
val messages by +state<List<Message>> { emptyList() }
fun onButtonClicked() {
algebra.getMessages().continueOn(UIContext).unsafeRunAsync { cb ->
cb.fold(
ifRight = {
messages = messages + it
},
ifLeft = { throw it }
)
}
}
}
// whatever you were doing before...
}Leland Richardson [G]
11/01/2019, 5:12 PMLeland Richardson [G]
11/01/2019, 5:12 PMaballano
11/01/2019, 5:13 PMLeland Richardson [G]
11/01/2019, 5:13 PMmessages = messages + it works just fineLeland Richardson [G]
11/01/2019, 5:13 PMLeland Richardson [G]
11/01/2019, 5:14 PMLeland Richardson [G]
11/01/2019, 5:14 PMLeland Richardson [G]
11/01/2019, 5:14 PMListLeland Richardson [G]
11/01/2019, 5:14 PMaballano
11/01/2019, 6:28 PMvar, right? otherwise how do you tigger an update without mutability?aballano
11/01/2019, 6:31 PMval (messages, messagesChanges) = +state<List<Message>> { emptyList() }Leland Richardson [G]
11/01/2019, 6:33 PMLeland Richardson [G]
11/01/2019, 6:33 PMvar if you’re using it as a property delegateaballano
11/01/2019, 6:37 PMLeland Richardson [G]
11/01/2019, 6:39 PMLeland Richardson [G]
11/01/2019, 6:39 PMLeland Richardson [G]
11/01/2019, 6:39 PMdisposeComposition in onDestroyLeland Richardson [G]
11/01/2019, 6:39 PMLeland Richardson [G]
11/01/2019, 6:40 PM+onDispose { ... }aballano
11/01/2019, 6:41 PMLeland Richardson [G]
11/01/2019, 6:41 PMLeland Richardson [G]
11/01/2019, 6:42 PM+onCommit { ... }Leland Richardson [G]
11/01/2019, 6:42 PMonCommit has its own onDisposeLeland Richardson [G]
11/01/2019, 6:42 PMLeland Richardson [G]
11/01/2019, 6:42 PM+onCommit {
myThing.subscribe(...)
onDispose { myThing.unsubscribe(...) }
}Leland Richardson [G]
11/01/2019, 6:43 PMLeland Richardson [G]
11/01/2019, 6:43 PMmyThing was a parameterLeland Richardson [G]
11/01/2019, 6:43 PM+onCommit(myThing) {
myThing.subscribe(...)
onDispose { myThing.unsubscribe(...) }
}
and then this will only call the body of onCommit whenever myThing changesLeland Richardson [G]
11/01/2019, 6:44 PMLeland Richardson [G]
11/01/2019, 6:44 PMLeland Richardson [G]
11/01/2019, 6:44 PMonActive which happens on the first composition only. This is equivalent to onCommit(someConstant)Leland Richardson [G]
11/01/2019, 6:45 PMmainContent(MainModel(messages), ::onButtonClicked)
did you wrap messages in MainModel?aballano
11/01/2019, 6:49 PMLeland Richardson [G]
11/01/2019, 6:54 PMLeland Richardson [G]
11/01/2019, 6:55 PMLeland Richardson [G]
11/01/2019, 6:55 PMval model = +memo { MainModel() }Leland Richardson [G]
11/01/2019, 6:55 PMmodel.messages = messages + itLeland Richardson [G]
11/01/2019, 6:55 PMaballano
11/01/2019, 6:59 PMLeland Richardson [G]
11/01/2019, 7:02 PMLeland Richardson [G]
11/01/2019, 7:02 PMLuca Nicoletti
11/01/2019, 7:03 PMdo you need to wrap aAnswer is yes?annotated class with@Modelormemoor the annotation does it for you already?state
aballano
11/01/2019, 7:06 PM+memo { MyModel("text") }
or
+state { "text" } if you don't need the MyModel wrapperLeland Richardson [G]
11/01/2019, 7:06 PMLeland Richardson [G]
11/01/2019, 7:06 PMLuca Nicoletti
11/01/2019, 7:06 PMLeland Richardson [G]
11/01/2019, 7:06 PMLuca Nicoletti
11/01/2019, 7:07 PM+state wrap the value you provide in a State instance, which is a @Model annotated classLeland Richardson [G]
11/01/2019, 7:07 PMLuca Nicoletti
11/01/2019, 7:07 PMLeland Richardson [G]
11/01/2019, 7:07 PMaballano
11/01/2019, 7:07 PMLuca Nicoletti
11/01/2019, 7:07 PMLuca Nicoletti
11/01/2019, 7:07 PMLuca Nicoletti
11/01/2019, 7:08 PM