Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazySet is not triggering update events #67

Open
xmlking opened this issue May 23, 2021 · 2 comments
Open

lazySet is not triggering update events #67

xmlking opened this issue May 23, 2021 · 2 comments
Labels

Comments

@xmlking
Copy link

xmlking commented May 23, 2021

val handler = Account.maxRetry.onSet { value -> println("the maxRetry has changed to $value") }
val handler2 = Account.maxRetry.beforeSet { config, value -> println("the maxRetry will change to $value") }
val handler3 = config.beforeSet { item, value -> println("${item.name} will change to $value") }

val maxRetry by config.property(Account.maxRetry)
println(maxRetry)
config.lazySet(Account.maxRetry) { 4 }
println(maxRetry)
config[Account.maxRetry] = 6
println(maxRetry)
3
4
the maxRetry has changed to 6
the maxRetry will change to 6
maxRetry will change to 6
6
@uchuhimo
Copy link
Owner

@xmlking It is difficult to decide how lazySet triggers onSet.

  • If we trigger onSet when config.lazySet(Account.maxRetry) { 4 }, we have to evaluate { 4 }, which may be an expansive/non-deterministic calculation.
  • If we trigger onSet when println(maxRetry), we have to trigger for every get operation of maxRetry.

Maybe the better solution is to add a new onLazySet API.

Which solution do you prefer?

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.

@stale stale bot added the stale label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants