[L2Ork-dev] rfc: tiny gui interface

Jonathan Wilkes jancsika at yahoo.com
Fri Nov 17 03:43:41 UTC 2017


Ok, a quick example:
function scope_configure_fg_old(cid, tag, type, data_array) {
    var g = get_gobj(cid, tag),
        fg_path = g.querySelector(type); // class ".fgxy" or ".fgmono"
    configure_item(fg_path, {
        d: data_array.join(" ")
    });
}

with the new interface, this becomes:
function scope_configure_fg(cid, tag, type, data_array) {
    gui(cid)
        .get_gobj(tag)
        .q(type, { // class ".fgxy" or ".fgmono"
            d: data_array.join(" ")
    });
}

Fewer variables, but more importantly the two aren't functionally equivalent.
In the old version, if either the patch or the object does not yet exist, it can 
potentially cause an error. Even if we added a null check in "get_gobj", notice 
that we have a native DOM method below that which would also have to be 
wrapped in a check.
In the new versiona) if the window does not yet exist, all the methods of "gui" will simply be ignored.b) all methods return a reference to the interface so you can chain things without 
running into null errors.
In addition to objects you can also send a function callback for more complex needs.Also, there's an "append" method that leverages a documentFragment in order to 
more efficiently mutate the DOM.
-Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://disis.music.vt.edu/pipermail/l2ork-dev/attachments/20171117/1d19253c/attachment-0001.html>


More information about the L2Ork-dev mailing list