79 Field subscriptions
onChange receives the previous and new field values after an assignment. close() stops later notifications, while the assignment itself still updates the field.
norm
import std.observation.onChange
class Task { String title = "Draft" }
main() {
Task task = Task()
var subscription = task.title.onChange {
printLine(oldValue + " -> " + newValue)
}
task.title = "Done"
subscription.close()
task.title = "Archived"
printLine(task.title)
}Expected output:
text
Draft -> Done
ArchivedTry it: Assign Done twice before closing and observe equal-value filtering.
Precise rules: Reference.