Function setup

  • Sets up the specified element(s) with the given arguments.

    The values in args are interpreted as follows:

    1. string, number and Node values are appended to the element
    2. functions values are called with the element as the sole argument
    3. object values are used to assign properties using Object.assign

    This function is also used internally to set up new elements created with e.

    Note that because of how Node appends work, any nodes args will end up appended only to the last element in elements (if they are more than one). Conversely, any fragments in args will have their nodes only appended to the first element in elements.

    Parameters

    • elements: Element | Iterable<Element>

      the element(s) to setup

    • Rest ...args: any[]

      the setup arguments

    Returns ((elements, ...args) => (elements: Element | Iterable<Element>, ...args: any[]) => typeof setup)

    this same function to support chaining multiple setup calls.

      • (elements, ...args): (elements: Element | Iterable<Element>, ...args: any[]) => typeof setup
      • Sets up the specified element(s) with the given arguments.

        The values in args are interpreted as follows:

        1. string, number and Node values are appended to the element
        2. functions values are called with the element as the sole argument
        3. object values are used to assign properties using Object.assign

        This function is also used internally to set up new elements created with e.

        Note that because of how Node appends work, any nodes args will end up appended only to the last element in elements (if they are more than one). Conversely, any fragments in args will have their nodes only appended to the first element in elements.

        Parameters

        • elements: Element | Iterable<Element>

          the element(s) to setup

        • Rest ...args: any[]

          the setup arguments

        Returns (elements: Element | Iterable<Element>, ...args: any[]) => typeof setup

        this same function to support chaining multiple setup calls.

        Example

        import { setup, e } from 'deleight/apriori';
        const tree = document.querySelector('main');
        setup(
        main,
        e.h1('Title',
        h1 => console.log(h1, ' created')
        ),
        e.section(
        e.h2('Section 1'),
        e.p(
        'This is the first section',
        { className: 'text-centre' }
        )
        )
        );

    Example

    import { setup, e } from 'deleight/apriori';
    const tree = document.querySelector('main');
    setup(
    main,
    e.h1('Title',
    h1 => console.log(h1, ' created')
    ),
    e.section(
    e.h2('Section 1'),
    e.p(
    'This is the first section',
    { className: 'text-centre' }
    )
    )
    );