βοΈ A lightweight Android lifecycle-aware and thread-safe pipeline for communicating between components with custom scopes.
π Released a new version 1.0.3
! π
PropertyObserver
annotation that used to observe value changes by ChamberProperty
that has the same key
value. This annotation only works with a method that in a scoped class. A method that is annotated with PropertyObserver
will be invoked, whenever the value changes and receives the value as a parameter. The method must have one parameter and the type must same as the generic of the ChamberProperty
.@UserScope // custom scope
class MainActivityViewModel : ViewModel() {
@ShareProperty(key = UserScope.nickname)
var username = ChamberProperty("skydoves")
@PropertyObserver(key = UserScope.nickname)
fun usernameObserver(value: String) {
Log.d("MainActivityViewModel", "usernameObserver: $value")
}
}
Here is an example of usages in an Activity.
@UserScope
class MainActivity : AppCompatActivity() {
@ShareProperty(key = UserScope.nickname)
private var username = chamberProperty("skydoves")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
shareLifecycle()
username.observe { Log.d("SecondActivity", "observed data: $it") }
username.value = "skydoves on SecondActivity"
}
@PropertyObserver(key = UserScope.nickname)
fun nickNameObserver(nickname: String) {
Log.d("MainActivity", "nickNameObserver: $nickname")
}
}
autoClear
to clearOnDestroy
. (52cf96bc)implemented autoClear option for clear the value on the local storage when lifecycle state is onDestroy.
autoClear(value: Boolean)
method on the ChamberField
.autoClear
option on the @ShareProperty
annotation. The default value is false.ππpublished first release version 1.0.0
ππ