kaushikgopal / movies-usf-android Goto Github PK
View Code? Open in Web Editor NEWMovie searching using a Unidirectional State Flow pattern for Android
License: Apache License 2.0
Movie searching using a Unidirectional State Flow pattern for Android
License: Apache License 2.0
I assume this annotation makes the class open. But how? Do you have some annotation processor running?
As in dependencies.gradle
Is this a good practice?
Just a thought for folks using this pattern.
Instead of having this nested when statements for Result to State and Result to Effect conversion, base Result could have functions to convert it to State (given current state) and to Effect.
With this in place, VM can just invoke a generic result.toState(currentState) and result.toEffect(). Any new Event and Result can be coded in place without having the lengthy conversion function. VM will just need additional logic to convert event to results.
Problem:
spaces in search not working.
Example:
When I search Godfather , it works. (but it shows Malayalam movie)
When I search "The Godfather" , it works
When I search The Godfather , it shows Invalid API key!
Suggestion:
Surround the entire search string with " " before making request.
return movieApi.searchMovie("\""+movieName+"\"")
instead of
return movieApi.searchMovie(movieName)
at
https://github.com/kaushikgopal/movies-usf-android/blob/master/app/src/main/java/co/kaush/msusf/movies/MSMovieRepository.kt#L13
Why do you use MS prefix everywhere?
Is this repo sponsored by Microsoft? ;-)
why not using the scan operator instead of
private val _viewState = MutableStateFlow(initialState)
override val viewState = _viewState.asStateFlow()
Hello kaushik, I have a question regarding the unidirectional state flow architecture. The implementation that you have done with rxjava in movies-usf is really good
, really appreciated that. One of my confusion is the way we pass the view state from viewmodel. Since, you are passing the entire state from the ViewModel, if the state is complex, then even a small change like changing the title can render the entire view. I also followed #14 where you mentioned of using diffing tool. I was wandering if we could use some wrapper around each attributes in the viewstate like NullBox (for nullables in rxjava) to identify if the state has changed or not, may be a wrapper with a boolean? This way we can check in the view weather the attributes in the state has changed or not and render only the changed ones.
The view state tests are the more interesting ones imho, but for this to be fully "complete", we'd definitely need UI instrumentation tests to make sure:
A single espresso tests should suffice for that.
When I try to build this on Android Studio 3.3.2, I get an error:
> Task :app:kaptReleaseKotlin FAILED
e: /Users/barry.sia/src/open/movies-usf/app/build/tmp/kapt3/stubs/release/co/kaush/msusf/MSApp.java:6: error: incompatible types: NonExistentClass cannot be converted to Annotation
@error.NonExistentClass()
^
e: /Users/barry.sia/src/open/movies-usf/app/build/tmp/kapt3/stubs/release/co/kaush/msusf/movies/MSMovieRepository.java:6:
error: incompatible types: NonExistentClass cannot be converted to Annotation
@error.NonExistentClass()
^
I'm running into an edge case and wanted to pick your brain on this, here is the use case
UI Event triggers a slow network op which starts with a loading state
UI is updated with a progress indicator
User backgrounds the app
Network op finishes while the app is in background (assume no process kill by android)
UI is subscribed to changes until onDestroy and gets notified of a navigation effect
Navigation Effect tries to perform fragment transaction while the app is paused
Things go haywire from here.
One approach to solve this was by having UI subscribe only until onPause and resubscribe from onResume. However, with this the effect notification is lost (no active subscriptions from paused state) when slow network op finishes while the app is backgrounded and re-subscription onResume fails as effect has no replay behavior from the view model.
This is kind of forcing navigation changes into view state. How do you go about this?
In the event flow process, it's sometimes required to execute side effects as a result of some action.
In my real world usage at Instacart, I had the following requirement:
so we'd need a way to send back new "events" into the events-> results function. Basically we need a side-effect introduced without necessarily making the function "impure"
I'll have to come up with an example that works in this movie search case. Probably have a polling endpoint that shows a random recommendation for a movie, every 1 minute. If recommendations are available, allow those to be clicked and added to the history list as well.
I see that whenever there is a change in state you are setting all Views, Adapter anew. In my MVVM code I have LiveData object for small state chunks and I update them separate from each other. How would you achieve the same in MVI?
@kaushikgopal - Thanks for the demo app. Quick question - according to you, what would be the best practice if we need to manage screen navigations with USF? For eg. in this demo app (movies-usf) if there is a button (say, "Details") that launches a new activity which shows the movie details, how will you integrate that button click event into this entire pattern? Thanks again!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.