Skip to content

1.0.3

Latest
Compare
Choose a tag to compare
@skydoves skydoves released this 15 May 03:09
· 1 commit to master since this release
b324008

🎉 Released a new version 1.0.3! 🎉

What's New?

  • Added 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")
  }
}
  • Renamed autoClear to clearOnDestroy. (52cf96b)
  • Prevented exposing some internal functionalities to outside.
  • Refactored internal codes.