vUX · Component · bring your own component

One template.
As many live instances as you like.

Write the markup once, mark it up with data-v-* bindings, and hand it to Component. You get cloning, field binding, event wiring and teardown, over your own HTML, styled by your own stylesheet.

const card = new Component($$.ss("#userCardTpl"));  ·  card.mount(container, data)

01Instances of one template

Every card below is a clone of the same <template>. Mounting returns an Instance: an object with its own node, its own data, and its own update() and destroy(). The template itself is never touched.

live instances 0 mounted
ready

The Pin and Remove buttons are wired through data-v-on, not through any listener this page attached. Their handlers live in config.handlers and are handed the instance's current data.

02Every binding, live

Each control writes one field through instance.update(). Only the bindings whose value actually moved are written to the DOM: the rest are left alone.

fields
rendered -

            

The pill above the card reports what update() returned: the list of field names that changed. Edit a field to a value it already holds and it reports nothing: no DOM write happens.

03Keyed lists keep their nodes

sync() matches data to instances by config.key. Rows that survive are moved, not rebuilt, so anything the browser owns inside them survives too.

componentObj.sync(container, rows)4 rows

Try this: type into a row's text box, then press sort by score. The row moves and your text moves with it. Then press rebuild, which throws the instances away and mounts fresh ones, and the text is gone. That difference is the whole point of keying.

    ready

    04Nesting, and letting go cleanly

    A child mounted through instance.mount() is owned by its parent. Destroy the parent and the children go with it: including the vUX components attached in onMount.

    lifecycle log0 live

    Each board attaches a ToolTip in onMount and calls its destroy() in onDestroy: hover a chip to see it. Before v4.0.0 most vUX components had no destroy() to call, which is why this module waited on that work. The log records every mount, update and destroy as it happens.

    05What it refuses to do

    Every button below deliberately misuses the API. The real thrown Error is printed verbatim: nothing here is a canned string.

    arg

    Bad constructor argument

    The constructor takes an element, not a selector or an id.

    order

    Used before initialize()

    The template is resolved by initialize(); nothing works before it.

    bind

    Template the page cannot honour

    A binding naming a handler that was never supplied, or a malformed pair.

    ref

    Unknown ref

    Asking for a data-v-ref the template does not carry lists the ones it does.

    key

    Keying mistakes

    A list needs a key, and the key has to be unique and present.

    life

    Destroyed instances

    An instance that has been destroyed refuses to be updated again.

    No error raised yet: press one of the buttons above.