🎉 Released a new version 1.0.3
! 🎉
What's New?
- Added
PropertyObserver
annotation that used to observe value changes byChamberProperty
that has the samekey
value. This annotation only works with a method that in a scoped class. A method that is annotated withPropertyObserver
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 theChamberProperty
.
@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")
}
}
- Renamed
autoClear
toclearOnDestroy
. (52cf96b) - Prevented exposing some internal functionalities to outside.
- Refactored internal codes.