https://kotlinlang.org logo
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by
Title
a

Archie

07/29/2020, 3:25 PM
Hi, I found
Kotlin Redux
a few days back and now Im starting to learn and study it. I understand the concepts very well but I just can't get how to model the
AppState
right. How exactly do you model the
AppState
? Examples I've seen so far only show a small application where the
AppState
is very simple. But how do you model an
AppState
in a Large Application with multiple screens? Do I make smaller "`AppState`" inside the "root"
AppState
like:
data class AppState(
    val loginAppState: LoginAppState,
    val signUpAppState: SignUpAppState
    val someOtherScreenAppState: OtherScreenAppState
    ....
)

data class LoginAppState(
    val usernamer: String,
    val password: String
    ....
)
It seems that 
Redux
 makes sense when screens share state between screens such as the Todo Application Example or its very simple when dealing with single screen application such as the Counter Application but how do you model the 
AppState
 when working with screens doesn't really have connected state such as an application with a 
LoginScreen
 and 
SignUpScreen
. Those two screens doesn't share any state. How to deal with these kinds of scenarios? I'd really appreciate any help. Thank you very much in advance
w

willyrs

07/29/2020, 3:50 PM
you should split your state instead of creating multiple stores, it doesn’t matter if screens share state or not
😮 1
you can tecnhically make different stores, but I never felt the need of it, in fact I feel like it would be more complicated than beneficial
every screen is attached to their sub-state anyway
from redux.js page: it is possible to create multiple distinct Redux stores in a page, but the intended pattern is to have only a single store. Having a single store enables using the Redux DevTools, makes persisting and rehydrating data simpler, and simplifies the subscription logic.
😮 1
g

George Theocharis

07/30/2020, 10:39 AM
Yes with substates as properties of the app state. Furthermore, your AppReducer would also delegate the state and the action to the responsible reducers.
😮 1
a

Archie

07/30/2020, 10:48 AM
can you guys link me to some examples? I also imagine that by putting everything in the
AppState
I will also have to manage when those `State`s get cleaned up. So in a
SignUpScreen
where you have User details, once the User is logged-in or have moved out of the SignUpScreen I would need to have an
Action
which would be interpreted by a reducer to clear the state. Is that correct?
g

George Theocharis

07/30/2020, 11:03 AM
Yes. Actually redux architectures have a pretty cumbersome boilerplate but the benefit is that everything is far easier to interact with. I don’t have an example currently to link but I have used it on a previous company.
😮 1
w

willyrs

07/30/2020, 11:06 AM
You shouldn’t rely on your state for the app navigation or include it in the state, I don’t feel the need of “resetting” the “SignupScreenState” when the user logs in, what for? That screen is removed from the UI by the navigation logic, so what’s the need of resetting its state? It’s not doing anything anyway. You just need to reset the state when you want to open that section again
a

Archie

07/30/2020, 11:19 AM
But imagine a state which contains a list of data. If that data is big, keeping it in there without the intention of ever using it again is wasteful specially for devices who have limited resources.
w

willyrs

07/30/2020, 11:24 AM
yes, in that case you should make an action that resets it, but I still feel like it’s more an exception than a rule
the only reset system that I have in my app is when the user logs out. The LOGOUT action is handled by every reducer and they reset their own sub-state individually
😮 1
I have a multiplatform project in progress, but -in fact- it’s still in progress so I only have one state for now: https://github.com/EmmanueleVilla/apod-kmp
❤️ 1
but adding another state is just a matter of creating state, action, reducer etc and adding it to the AppState: data class AppState(val homeState: HomeState = HomeState())
❤️ 1
you can find the “root” redux classes here: apod-kmp/shared/src/commonMain/kotlin/com/shadowings/apodkmp/redux/ and the “home section” redux classes here: apod-kmp/shared/src/commonMain/kotlin/com/shadowings/apodkmp/home/
❤️ 1
a

Archie

07/30/2020, 11:29 AM
ok one last question i guess.. how do i manage the smaller States? The way I learned how to create the AppState is to do something like:
data class AppState(
    val someState: SomeState = reducerSomeState(action),
        val someState: SomeState = reducerAnotherState(action)
     ....
)

// I cant imagine how to do it for the state inside the substate
data class SomeState(
    val somthing: String = reducerSomething(action)
    ....
w

willyrs

07/30/2020, 11:29 AM
i dont get it, you want to create a substate of a substate?
a

Archie

07/30/2020, 11:30 AM
Maybe I should look into your example first and ask again. 🙂 Your work might answer my questions. This is a very big help! Thank you very much. I really appreciate it! ❤️
w

willyrs

07/30/2020, 11:31 AM
don’t worry, feel free to ask again 🙂 One day I will add more sections, I still need to finish iOS and start React
❤️ 1
a

Archie

07/30/2020, 11:31 AM
Thank you so much 😄
👍 1
Hi @willyrs, I looked into your work. I saw that you only have a single reducer for
HomeState
I was wondering how you'd scale it once
HomeState
gets bigger.
w

willyrs

07/30/2020, 1:35 PM
HomeState only represents the HomeScreen, so it won’t get bigger than the screen itself. Every part of the app should have its own state with all the information it needs. I never needed a state with more than a couple of properties, do you feel like you could have all that data needed in a single screen?
a

Archie

07/30/2020, 1:36 PM
is it correct to do something like:
fun homeReducer(state: HomeState, action: Any): HomeState {
    return HomeState(
        latest = reduceHomeLatest(action),
        something = reduceSomething(action),
        ....
    )
}
w

willyrs

07/30/2020, 1:37 PM
no, every part of the state should have only one reducer. Depending on the library it could even don’t compile, for example with redux.js you need to have a 1:1 state-reducer
p

patjackson52

08/07/2020, 3:41 PM
I’ve always used a single, global store. Nothing is stopping you from using multiple stores. Mutiple stores are more of a flux arch (from web). Redux-kotlin is not really opinionated, , so what ever works for you and your team. I say a store has the benefit of easily sharing state between views/screens/etc. True, it could present memory pressure in some use cases. Really depends on the app and what is in the store. Larger/memory intesive stores may need to prune state if leaving an area of the app, or if device signals low memory (onTrimMemory() on Android for example)