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

    mysterious-toddler-20573

    12/12/2020, 7:44 PM
    https://wtmatter.com/python-simple-http-server/
  • m

    mysterious-toddler-20573

    12/12/2020, 7:44 PM
    You just open up test/index.html
  • f

    future-boots-43048

    12/12/2020, 7:45 PM
    Oh, that's nice and easy.
  • m

    mysterious-toddler-20573

    12/12/2020, 7:45 PM
    but it has to be in a web browser environment
  • m

    mysterious-toddler-20573

    12/12/2020, 7:45 PM
    you can't open it from the file system due to security stuff
  • f

    future-boots-43048

    12/12/2020, 7:45 PM
    I thought I'd have to install Node and about a million dependencies.
  • m

    mysterious-toddler-20573

    12/12/2020, 7:45 PM
    NOT ON MY WATCH
  • f

    future-boots-43048

    12/12/2020, 7:45 PM
    yaaay!
  • f

    future-boots-43048

    12/12/2020, 7:46 PM
    Man after my own heart.
  • f

    future-boots-43048

    12/12/2020, 7:52 PM
    Copy code
    index.html:6 GET http://localhost:8000/node_modules/mocha/mocha.css net::ERR_ABORTED 404 (File not found)
    index.html:61 GET http://localhost:8000/node_modules/chai/chai.js net::ERR_ABORTED 404 (File not found)
    index.html:62 GET http://localhost:8000/node_modules/mocha/mocha.js net::ERR_ABORTED 404 (File not found)
    index.html:63 GET http://localhost:8000/node_modules/sinon/pkg/sinon.js net::ERR_ABORTED 404 (File not found)
  • f

    future-boots-43048

    12/12/2020, 7:54 PM
    I'm going to see if I can just download those myself.
  • f

    future-boots-43048

    12/12/2020, 8:08 PM
    Huh. Not so easy. Maybe I do need to install them with Node after all.
  • m

    mysterious-toddler-20573

    12/12/2020, 8:12 PM
    ah, yeah, you do need to do an npm install for the testing framework :/
  • f

    future-boots-43048

    12/12/2020, 9:16 PM
    Okies. Had a bit of a break, but the tests work, and I've updated the PR.
  • f

    future-boots-43048

    12/12/2020, 9:16 PM
    I'm not going to do anything more on the PR for the moment.
  • f

    future-boots-43048

    12/12/2020, 9:17 PM
    I'm just going to try to use it like this for a while and see if it actually works well for my use case.
  • m

    mysterious-toddler-20573

    12/12/2020, 9:50 PM
    OK, you want me to wait on accepting?
  • f

    future-boots-43048

    12/12/2020, 10:00 PM
    Yeah. Hold off on accepting for the moment.
  • f

    future-boots-43048

    12/12/2020, 10:01 PM
    I want to make sure it actually works in anger, first.
  • f

    future-boots-43048

    12/12/2020, 10:02 PM
    Consider it 'acceptance testing'.
  • f

    future-boots-43048

    12/12/2020, 10:47 PM
    Now all I need to do is to figure out how to 'register' a new callback function when it gets swapped back in.
  • m

    mysterious-toddler-20573

    12/12/2020, 11:16 PM
    🤔
  • m

    mysterious-toddler-20573

    12/12/2020, 11:16 PM
    tell me more
  • f

    future-boots-43048

    12/12/2020, 11:18 PM
    Well ... this is what I do right now ...
  • f

    future-boots-43048

    12/12/2020, 11:19 PM
    This is how I stream HTML UI components using the htmx sse swap:-
  • f

    future-boots-43048

    12/12/2020, 11:19 PM
    Copy code
    # -----------------------------------------------------------------------------
    def sse_swapping_streamer(list_id_ui, **kwargs):
        """
        Return a list of divs that display a 'live view' of the given resources.
    
        Requires the containing branch
        in the DOM to be subscribed to
        SSE (Server Side Event) updates
        for the specified resource.
    
        """
        list_tag = []
        for id_ui in list_id_ui:
            tag_div = xact.lib.ui.web.markup.html.div(
                                data_hx_sse     = 'swap:{id}'.format(id = id_ui),
                                data_hx_trigger = 'load',
                                data_hx_get     = '/{id}'.format(id = id_ui),
                                **kwargs)
            list_tag.append(tag_div)
        return list_tag
  • f

    future-boots-43048

    12/12/2020, 11:19 PM
    And this is how I'm trying to stream data to a javascript function:-
  • f

    future-boots-43048

    12/12/2020, 11:19 PM
    Copy code
    # -----------------------------------------------------------------------------
    def sse_callback_streamer(id_res, js_callback, **kwargs):
        """
        Return a divs for scripted display of the given resources.
    
        """
        name_fcn   = 'window.xact_{id}'.format(id = id_res)
        tag_script = xact.lib.ui.web.markup.html.inline_script(
                                        '{fcn} = {js}'.format(fcn = name_fcn,
                                                              js  = js_callback))
        tag_div    = xact.lib.ui.web.markup.html.div(
                        id              = id_res,
                        data_hx_trigger = 'sse:{id}'.format(id = id_res),
                        data_hx_sse     = 'listen:{id}'.format(id = id_res),
                        data_script     = 'on {evt} call {fcn}({args})'.format(
                                                        evt  = 'htmx:sseMessage',
                                                        fcn  = name_fcn,
                                                        args = '(event)'))
        return (tag_script, tag_div)
  • f

    future-boots-43048

    12/12/2020, 11:20 PM
    It's not really an htmx problem ...
  • f

    future-boots-43048

    12/12/2020, 11:20 PM
    But the inline script is only executed the first time that it's seen.
1...9899100...1146Latest