cloudnode-pro / components

Base classes for web components
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Accept undefined/null in `append()` #10

Closed zefir-git closed 1 week ago

zefir-git commented 1 week ago

Accept undefined/null in append() so that conditional appending is possible, without leaving the component method chain. Example:

// Current beheaviour
private method(foo: Component, bar: Component, baz?: Component) {
    const div = new Component("div")
        .append(foo);
    if (baz) div.append(baz);
    div.append(bar);
    return div;
}

// Proposed new behaviour
private method(foo: Component, bar: Component, baz?: Component) {
    return new Component("div")
        .append(foo)
        .append(baz)
        .append(bar);
}

The idea is to enable the use of:

.append(boolean ? Component : null)