https://htmx.org logo
Join Discord
Powered by
# htmx-general
  • m

    mysterious-toddler-20573

    12/12/2020, 3:39 PM
    https://github.com/bigskysoftware/htmx/pull/263#pullrequestreview-550839041
  • m

    mysterious-toddler-20573

    12/12/2020, 3:39 PM
    a few comments on the code
  • m

    mysterious-toddler-20573

    12/12/2020, 3:39 PM
    mostly aesthetic stuff
  • m

    mysterious-toddler-20573

    12/12/2020, 3:39 PM
    but this seems like the right thing to me
  • m

    mysterious-toddler-20573

    12/12/2020, 3:40 PM
    One thought: would it make sense to have the events say if they were a swap or not?
  • m

    mysterious-toddler-20573

    12/12/2020, 3:40 PM
    w/ a property?
  • m

    mysterious-toddler-20573

    12/12/2020, 3:40 PM
    Or is it better to have this done on the client side...
  • m

    mysterious-toddler-20573

    12/12/2020, 3:40 PM
    I don't know what the
    event.data
    object looks like...
  • m

    mysterious-toddler-20573

    12/12/2020, 3:40 PM
    is it a string? Or a javascript object?
  • f

    future-boots-43048

    12/12/2020, 3:40 PM
    I want to think about this a bit more first ...
  • f

    future-boots-43048

    12/12/2020, 3:41 PM
    This is definitely not oven-ready.
  • m

    mysterious-toddler-20573

    12/12/2020, 3:41 PM
    that's fine
  • m

    mysterious-toddler-20573

    12/12/2020, 3:41 PM
    this is the fun part, where the rubber meets the road!
  • f

    future-boots-43048

    12/12/2020, 3:42 PM
    What might actually make more sense is just directly calling a javascript function...
  • f

    future-boots-43048

    12/12/2020, 3:43 PM
    This is what it looks like on the back end right now:-
  • f

    future-boots-43048

    12/12/2020, 3:43 PM
    Copy code
    with html.div(
                _class = ('shadow-xl',
                          'rounded-3xl',
                          'bg-yellow-50',
                          'text-gray-900',
                          'hover:bg-yellow-500',
                          'hover:text-white',
                          'p-5')) as datacard:
    
            jscript = """function(id, evt) {
                //d3.select(evt.detail.elt).html(evt.detail.data);
                console.log(evt.detail.elt);
            }"""
    
            html.inline_script('window.xact_{id} = {js}'.format(id = id_res,
                                                                js = jscript))
            with html.div(id              = id_res,
                          data_hx_trigger = 'sse:{id}'.format(id = id_res),
                          data_hx_sse     = 'forward:{id}'.format(id = id_res),
                          data_script     = ('on {id} call window.xact_{id}'
                                             '("{id}", event)').format(
                                                                    id = id_res)):
                svg.svg(width  = 100,
                        height = 100,
                        style  = 'background: red')
    
        return datacard
  • f

    future-boots-43048

    12/12/2020, 3:43 PM
    ^ Very much test code.
  • l

    lively-beach-14291

    12/12/2020, 3:43 PM
    Oh. Yea, that's nice.
  • l

    lively-beach-14291

    12/12/2020, 3:43 PM
    @User Thanks.
  • f

    future-boots-43048

    12/12/2020, 3:44 PM
    But you can see that I'm using hyperscript to glue the SSE event back to an inline javascript function which renders the graph.
  • f

    future-boots-43048

    12/12/2020, 3:44 PM
    And it might make sense to just have something like data_hx_sse = 'call:function(event)' ...
  • f

    future-boots-43048

    12/12/2020, 3:44 PM
    Or something like that.
  • l

    lively-beach-14291

    12/12/2020, 3:44 PM
    @User Ya, you're using something like
    Hyperscript.jl
    .
  • f

    future-boots-43048

    12/12/2020, 3:44 PM
    But I'm very new at Javascript, and I've got to understand how that call would be resolved.
  • f

    future-boots-43048

    12/12/2020, 3:45 PM
    (Eventually, I also want to transpile that jscript string from Python using something like transcrypt)
  • f

    future-boots-43048

    12/12/2020, 3:46 PM
    It seems like writing a bunch of javascript just to avoid writing javascript is a bit of a meme
  • l

    lively-beach-14291

    12/12/2020, 3:46 PM
    The idea of using
    HypertextLiteral.jl
    is that you're using string interpolation to build HTML.
  • l

    lively-beach-14291

    12/12/2020, 3:46 PM
    Rather than a server-side DOM.
  • l

    lively-beach-14291

    12/12/2020, 3:47 PM
    ie
    htl"<span>My Name is $name</span>"
    would know to pull the contents of the
    name
    variable from current scope, escape it for content, and return the collected string
  • m

    mysterious-toddler-20573

    12/12/2020, 3:48 PM
    @User OK, let me chew on that code for a bit. There has to be a cleaner way than that.
1...959697...1146Latest