Observable: Basic API¶
Creating an Observable¶
from nuiitivet.observable import Observable
name = Observable("Alice")
age = Observable(20)
items = Observable([])
Getting and Setting Values¶
Subscribing and Unsubscribing¶
In most UI cases, cleanup is handled automatically by the framework lifecycle.
Custom Comparison Function¶
By default, value equality uses ==.
You can customize comparison behavior when needed.
always_notify = Observable(0, compare=lambda a, b: False)
def compare_users(a, b):
if a is None or b is None:
return a is b
return a.uid == b.uid
user = Observable(None, compare=compare_users)