state.a = 2 # assignations do not flush
state.update({'a': 1, 'b': 0}) # updates do not flush
state.dirty("c") # `dirty()` does not flush
state.flush() # flush happens here
with state:
state.d = 3
state.e = "lion"
# flush happens here, on `with` exit
state.f = 6
# will eventually automatically be flushed by the trame asyncio event loop
Does the last flush()
triggers ?
state.a = 0
state.flush()
state.a = 1
state.a = 0
state.flush()
→ no, because old and new values are the same: 0 == 0
Does the last flush()
triggers ?
state.a = []
state.flush()
state.a.append(10)
state.flush()
→ no, because a
did not change: ref([10]) == ref([10]])
.
To force a flush, use dirty("a")
Does the last flush()
triggers ?
state.a = []
state.flush()
state.a.append(10)
state.dirty("a")
state.flush()
→ yes, because dirty()
was called: ref([10]) == ref([10]])
but a is dirty
Does the last flush()
triggers b
?
state.a = []
state.b = state.a
state.flush()
state.dirty("a")
state.flush()
→ no, because dirty()
was called on a
only.
Does the last flush() triggers ?
state.a = [0]
state.flush()
state.a = [0]
state.flush()
→ no, because old and new values are the same: ref([0]) != ref([0])
but [0] == [0]
Does the last flush() triggers ?
state.a = (3.14957, 42)
state.flush()
state.a = (3.14957 + 0, 42)
state.flush()
→ no, because old and new values are the same: (3.14957, 42) == (3.14957, 42)
Trigger or not on last flush ?
state.a = 0
state.flush()
state.dirty("a")
state.flush()
→ yes, triggers because a is dirty
Trigger or not on last flush ?
state.a = 0
state.a = flush()
state.a = 1
state.dirty("a")
state.a = 0
state.flush()
→ no trigger because old and new values are compared
Infinite loop or not ? If not, what state.a is worth after the first flush()
?
@state.change("a")
def on_change(a, **kwargs):
state.a += 1
state.flush()
state.a = 1
state.flush()
→ ∞ infinite recursive loop
Infinite loop or not ? If not, what state.a is worth after the first flush()
?
@state.change("a")
def on_change(a, **kwargs):
state.a += 1
state.a = 1
state.flush()
→ ∞ infinite recursive loop
Infinite loop or not ? If not, what state.a and state.b are worth after the first flush()
?
@state.change("a")
def on_a_change(a, **kwargs):
state.b = a + 1
@state.change("b")
def on_b_change(b, **kwargs):
state.a = b + 1
state.a = 1
state.flush()
→ ∞ infinite recursive loop