Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def ComponentWithMemo():
location, set_location = idom.hooks.use_state("left")
memoized_func = idom.hooks.use_lru_cache(function_to_memoize, maxsize=2)
last_memoized_location = memoized_func(location)
async def on_left_button_click(event):
set_location("left")
async def on_center_button_click(event):
set_location("center")
async def on_right_button_click(event):
set_location("right")
return idom.html.div(
idom.html.button(
{"onClick": on_left_button_click, "id": "left-button"}, "left button"
),
idom.html.button(
{"onClick": on_center_button_click, "id": "center-button"},
"center button",
),
idom.html.button(
{"onClick": on_right_button_click, "id": "right-button"}, "right button"
),
f"Last triggered on click: {last_memoized_location}",
)
async def Counter(self, count):
finalize(self, was_garbage_collected.set)
return idom.html.div({"id": f"count-is-{count}"}, count)
def MyComponentWithChildrenAndAttributes(children, x):
return idom.html.div({"x": x * 2}, children + ["world"])
def MyComponentWithChildren(children):
return idom.html.div(children + ["world"])
async def ComponentWithMemo():
location, set_location = idom.hooks.use_state("left")
count = idom.hooks.use_memo(function_to_memoize, location)
async def on_left_button_click(event):
set_location("left")
async def on_right_button_click(event):
set_location("right")
return idom.html.div(
idom.html.button(
{"onClick": on_left_button_click, "id": "left-button"}, "left button"
),
idom.html.button(
{"onClick": on_right_button_click, "id": "right-button"}, "right button"
),
f"Memo trigger count: {count}",
)
async def EventLog(self, event=None):
return idom.html.div(
{"class": "highlight"}, idom.html.pre(json.dumps(event, indent=2))
)
style = idom.html.style(
[
"""
.linked-inputs {margin-bottom: 20px}
.linked-inputs input {width: 48%;float: left}
.linked-inputs input + input {margin-left: 4%}
"""
]
)
async def restart(event):
self.update()
restart_button = idom.html.button({"onClick": restart}, "Run It Again ♻️")
return idom.html.div(
{"style": {"width": "60%"}},
[restart_button, style, plot, mu_inputs, sigma_inputs],
)
def Grid(grid_size, block_size):
return idom.html.div(
{
"style": {
"height": f"{block_size * grid_size}px",
"width": f"{block_size * grid_size}px",
},
"tabIndex": -1,
},
[
idom.html.div(
{"style": {"height": block_size}},
[Block("white", block_size) for i in range(grid_size)],
)
for i in range(grid_size)
],
event_handlers=idom.Events(),
)
async def render(self) -> "VdomDict":
return idom.html.div(*self._children)