-
I'm just wondering about the mechanics of When the scope has left the Could one do something like the following to use CSS animations perhaps? with node.lock:
node.class_list.add('animate_in')
sleep(5)
with node.lock:
node.class_list.add('animate_out') Sorry not at computer but just occurred to me. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@mwx23 Excellent question! No. Locking has nothing to do with sending updates over the websocket, it's a mechanism to avoid race conditions between threads. Let's say we have a view with a counter that gets increased once a second, and there is a button to decrease the counter. The counter may be never lower than one (code is not tested). class CounterView(LonaView):
def handle_button_click(self, input_event):
with self.html.lock:
current_value = int(self.html[0].get_text())
value = current_value - 1
if value < 0:
value = 0
self.html[0].set_text(value)
def handle_request(self, request):
self.html = HTML(
Div(
'0',
_id='counter',
),
Button('-', _id='dec', handle_click=self.handle_button_click),
)
while True:
with self.html.lock:
current_value = int(self.html[0].get_text())
value = current_value + 1
self.html[0].set_text(value)
self.show(self.html)
self.sleep(1) First of all: To increase the counter by exactly one, Every operation on an Lona node pulls a lock implicitly. If From CSS animations: I wouldn't recommend to control timing sensitive animations from the Lona view directly. The locking mechanism ensures thread safety, but is not timing safe. I would use a frontend widget that uses some js code to control the animations and would use |
Beta Was this translation helpful? Give feedback.
@mwx23 Excellent question! No. Locking has nothing to do with sending updates over the websocket, it's a mechanism to avoid race conditions between threads.
Let's say we have a view with a counter that gets increased once a second, and there is a button to decrease the counter. The counter may be never lower than one (code is not tested).