Giter Club home page Giter Club logo

Comments (2)

akshayka avatar akshayka commented on June 21, 2024

Thanks for reporting, and for the reproduction.

On >= 0.5.2, the handler is being called, but I'm also seeing a bug in which the batched switch UI element is resetting after being clicked. Do you also see that?

Screencast.from.05-21-2024.03.15.14.PM.webm

from marimo.

akshayka avatar akshayka commented on June 21, 2024

@mrdobalina2k : Thanks for reporting, I have a fix out in #1439.

By the way, I figured out the flickering/resetting of the slider. It's because your on_change handler calls get_state(). To fix that, use the function API for set_state, like below:

import marimo

__generated_with = "0.6.0"
app = marimo.App()


@app.cell
def __():
    import marimo as mo
    return mo,


@app.cell
def __(mo):
    get_state, set_state = mo.state(0)
    return get_state, set_state


@app.cell
def __(mo, set_state):
    def on_change(value):
        # don't call `get_state` here!
        set_state(lambda v: v+1)

    switch = mo.ui.switch(value=True, on_change=on_change)
    return on_change, switch


@app.cell
def __(switch):
    switch
    return


@app.cell
def __(mo, switch):
    def wrap_switch(switch):

        wrapped = mo.md("""
        wrapped switch

        {switch}""").batch(switch=switch)
        return wrapped

    wrapped_switch = wrap_switch(switch)
    wrapped_switch
    return wrap_switch, wrapped_switch


@app.cell
def __(wrapped_switch):
    wrapped_switch._elements["switch"]._id
    return


@app.cell
def __(wrapped_switch):
    wrapped_switch.value
    return


@app.cell
def __():
    from marimo._runtime.context import get_context

    get_context().ui_element_registry._objects
    return get_context,


@app.cell
def __(get_state):
    get_state()
    return


if __name__ == "__main__":
    app.run()

from marimo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.