Don't wanna be here? Send us removal request.
Text
RxAndroid Learnings.
RxAndroid is a library that handles any asynchronous data streams.
What r async data streams:
click event
push notifications
keyboard input
reading a file
database access
device sensor updates
They happen at anytime and outside of normal flow of program execution.
Benefits of Rx:
Chaining
Abstraction
Threading
Non-blocking
Composable
avoid callbacks
data transformation
Function map does data transformation.
Example of Observable with data transformation:
Observable.just( 5, 6, 7 ) .map { “;-) “.repeat(it) } .subscribe { println(it) }
Result:
;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-)
Example of Observable with chaining:
Observable.just( 5, 6, 7 ) .map { “;-) “.repeat(it) } .filter { it.length < 24 } .subscribe { println(it) }
Result:
;-) ;-) ;-) ;-) ;-)
E.g. kotlin collections
Example:
listOf ( 5, 6, 7 ) .map { it * 5 } .filter { it > 25 }
Process:
5 6 7 map into
25 30 35
filter into
30 35
Disadvantage:
extra overhead
blocking async manner
LAZY - will not create intermediate list with same result.
listOf ( 5, 6, 7 ) .asSequence() .map { it * 5 } .filter { it > 25 } .toList()
RxJava vs Kotlin
in Rx is ok to not have any data initially. Rx is also lazy
Rx has flexible threading model. Can choose thread to do the work on by using Schedulers.
3 Basic of Rx (3o’s)
Observer
Observables
Operators
Observable
U can think of this as producing a stream of events that you are interested in knowing bout.
Observable can be Hot or Cold manner Hot: Start doing work as soon as it gets created. It is not waiting for anyone else before getting “busy”. Example: Click events
Cold: They dont work until someone shows interest. It doesnt work when it gets observable. Example: Reading a file - dont needa do work until someone wants to read a file
Observable.create<Int> { subscriber -> }
Observable.just( item1, item2, item3 )
Observable.interval( 2, TimeUnit.SECODNS )
@Test fun testCreate_withNoSubscriber() {
val observable = Observable.create<Int> { subscriber ->
Logger.log(”create”) subscriber.onNext(4) subscriber.onNext(5) subscriber.onNext(6)
Logger.log(”complete”)
}
Logger.log(”done”) }
================= main: done ================= it only prints “done”
@Test fun testCreate_withSubscriber() {
val observable = Observable.create<Int> { subscriber ->
Logger.log(”create”) subscriber.onNext(4) subscriber.onNext(5) subscriber.onNext(6)
Logger.log(”complete”)
} observable.subscribe { Logger.log( “next: $it” ) }
Logger.log(”done”) }
================= main: create main: next: 4 main: next: 5 main: next: 6 main: complete main: done ================= it only prints “done”
Observer
Observer is the abstraction that Rx java uses for listening to or observing the various items or events that the observable is producing.
interface Observer <T> {
fun onError( e: Throwable )
fun Complete()
fun onNext( t: T )
fun onSubscribe( d: Disposable )
}
Sometimes observer dont rly care bout other things.
interface Consumer <T> { fun accept( t: T ) }
accept method is like the onNext method
Observers: have a lifecycle. Subscribe, Next, Error, Complete
Operator
Operators are what help you to transform and combine / create observable
map()
Observable.just( 5, 6, 7) .map { “ ;-) ”.repeat( it ) } .subscribe { println( it ) }
function map expanded:
flatmap ()
flatmap transform an item into an Observable of different item for long running async task
e.g.
Flowable, Singles, Maybe, BackPressure, Completable, Disposable???
Should you use Rx?
do you like Function programming?
Process items asynchronously?
Compose data?
Handle errors gracefully?
If yes to most of this qns > it depends Rx java can be too complex to handle things u need.
src: https://www.youtube.com/watch?v=YPf6AYDaYf8 useful links: www.adavis.info
0 notes
Text
Realm & Mongo db
1. Works the way they think - in objects.
2. Feel objects - doesnt feel DB
3. Extras: observability, concurrency, transactions
4. Remove boilerplate
5. Realm can store: dictionaries, sets, Any/ mix
6. Realm has cascading deletes, inheritance, analytics and transformational queries
7. Realm support for more platforms
8. Universal sync solution
9. Cross device sync <iphone & android>
10. Unified for mobile and web.
11. Sharing data across friends > give read write access via the sync
0 notes
Text
System Architecture
“Decisions and designs must be made early”, no.
In reality, these decisions and designs are things that we wish we got it right earlier on. Truth is the decisions we might need to make early we don’t have the information, we only learn how the structure should be like when you’re building it.
https://www.youtube.com/watch?v=DngAZyWMGR0
0 notes
Text
What is system architecture?
Shared understanding of the system design of the expert developers.
It is the fuzzy embedded understanding that matters
There may be diagrams or documents here and there, there may be architecture written on them, but they are just a representation; usually imperfect representation of that shared understanding.
What really matters is that there is good shared understanding between the people leading the project.
https://www.youtube.com/watch?v=DngAZyWMGR0
1 note
·
View note