How to use the @lwc/shared.ArrayPush.call function in @lwc/shared

To help you get started, we’ve selected a few @lwc/shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github salesforce / lwc / packages / @lwc / synthetic-shadow / src / faux-shadow / traverse.ts View on Github external
export function getAllMatches(owner: Element, nodeList: Node[]): Array {
    const filteredAndPatched = [];
    for (let i = 0, len = nodeList.length; i < len; i += 1) {
        const node = nodeList[i];
        const isOwned = isNodeOwnedBy(owner, node);
        if (isOwned) {
            // Patch querySelector, querySelectorAll, etc
            // if element is owned by VM
            ArrayPush.call(filteredAndPatched, node);
        }
    }
    return filteredAndPatched;
}
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / polyfills / mutation-observer / polyfill.ts View on Github external
if (addedNodes.length > 0) {
                    // Optimization: Peek in and test one node to decide if the MutationRecord qualifies
                    // The remaining nodes in this MutationRecord will have the same ownerKey
                    const sampleNode: Node = addedNodes[0];
                    if (isQualifiedObserver(observer, sampleNode)) {
                        // If the target was being observed, then return record as-is
                        // this will be the case for slot content
                        if (
                            target[observerLookupField] &&
                            (target[observerLookupField][0] === observer ||
                                ArrayIndexOf.call(target[observerLookupField], observer) !== -1)
                        ) {
                            ArrayPush.call(filteredSet, record);
                        } else {
                            // else, must be observing the shadowRoot
                            ArrayPush.call(filteredSet, retargetMutationRecord(record));
                        }
                    }
                } else {
                    // In the case of removed nodes, climbing the tree is not an option as the nodes are disconnected
                    // We can only check if either the host or shadow root was observed and qualify the record
                    const shadowRoot = (target as Element).shadowRoot;
                    const sampleNode: Node = removedNodes[0];
                    if (
                        getNodeNearestOwnerKey(target) === getNodeNearestOwnerKey(sampleNode) && // trickery: sampleNode is slot content
                        isQualifiedObserver(observer, target) // use target as a close enough reference to climb up
                    ) {
                        ArrayPush.call(filteredSet, record);
                    } else if (
                        shadowRoot &&
                        shadowRoot[observerLookupField] &&
                        (shadowRoot[observerLookupField][0] === observer ||
github salesforce / lwc / packages / @lwc / engine / src / framework / wiring.ts View on Github external
function createContextWatcher(
    vm: VM,
    wireDef: WireDef,
    callbackWhenContextIsReady: (newContext: ContextValue) => void
) {
    const { adapter } = wireDef;
    const adapterContextToken = getAdapterToken(adapter);
    if (isUndefined(adapterContextToken)) {
        return; // no provider found, nothing to be done
    }
    const {
        elm,
        context: { wiredConnecting, wiredDisconnecting },
    } = vm;
    // waiting for the component to be connected to formally request the context via the token
    ArrayPush.call(wiredConnecting, () => {
        // This event is responsible for connecting the host element with another
        // element in the composed path that is providing contextual data. The provider
        // must be listening for a special dom event with the name corresponding to the value of
        // `adapterContextToken`, which will remain secret and internal to this file only to
        // guarantee that the linkage can be forged.
        const internalDomEvent = new CustomEvent(adapterContextToken, {
            bubbles: true,
            composed: true,
            detail(newContext: ContextValue, disconnectCallback: () => void) {
                // adds this callback into the disconnect bucket so it gets disconnected from parent
                // the the element hosting the wire is disconnected
                ArrayPush.call(wiredDisconnecting, disconnectCallback);
                // TODO: dev-mode validation of config based on the adapter.contextSchema
                callbackWhenContextIsReady(newContext);
            },
        });
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / polyfills / mutation-observer / polyfill.ts View on Github external
function patchedObserve(
    this: MutationObserver,
    target: Node,
    options?: MutationObserverInit
): void {
    // Maintain a list of all observers that want to observe a node
    if (isUndefined(target[observerLookupField])) {
        defineProperty(target, observerLookupField, { value: [] });
    }
    // Same observer trying to observe the same node
    if (ArrayIndexOf.call(target[observerLookupField], this) === -1) {
        ArrayPush.call(target[observerLookupField], this);
    } // else There is more bookkeeping to do here https://dom.spec.whatwg.org/#dom-mutationobserver-observe Step #7

    // If the target is a SyntheticShadowRoot, observe the host since the shadowRoot is an empty documentFragment
    if (target instanceof SyntheticShadowRoot) {
        target = (target as ShadowRoot).host;
    }

    // maintain a list of all nodes observed by this observer
    if (observerToNodesMap.has(this)) {
        const observedNodes = observerToNodesMap.get(this)!;
        if (ArrayIndexOf.call(observedNodes, target) === -1) {
            ArrayPush.call(observedNodes, target);
        }
    } else {
        observerToNodesMap.set(this, [target]);
    }
github salesforce / lwc / packages / @lwc / engine / src / framework / api.ts View on Github external
let iterationError: string | undefined;
    if (process.env.NODE_ENV !== 'production') {
        keyMap = ObjectCreate(null);
    }

    while (last === false) {
        // implementing a look-back-approach because we need to know if the element is the last
        next = iterator.next();
        last = next.done;

        // template factory logic based on the previous collected value
        const vnode = factory(value, j, j === 0, last);
        if (isArray(vnode)) {
            ArrayPush.apply(list, vnode);
        } else {
            ArrayPush.call(list, vnode);
        }

        if (process.env.NODE_ENV !== 'production') {
            const vnodes = isArray(vnode) ? vnode : [vnode];
            forEach.call(vnodes, (childVnode: VNode | null) => {
                if (!isNull(childVnode) && isObject(childVnode) && !isUndefined(childVnode.sel)) {
                    const { key } = childVnode;
                    if (isString(key) || isNumber(key)) {
                        if (keyMap[key] === 1 && isUndefined(iterationError)) {
                            iterationError = `Duplicated "key" attribute value for "<${childVnode.sel}>" in ${vmBeingRendered} for item number ${j}. A key with value "${childVnode.key}" appears more than once in the iteration. Key values must be unique numbers or strings.`;
                        }
                        keyMap[key] = 1;
                    } else if (isUndefined(iterationError)) {
                        iterationError = `Invalid "key" attribute value in "<${childVnode.sel}>" in ${vmBeingRendered} for item number ${j}. Set a unique "key" value on all iterated child elements.`;
                    }
                }
github salesforce / lwc / packages / @lwc / engine / src / framework / api.ts View on Github external
function addVNodeToChildLWC(vnode: VCustomElement) {
    ArrayPush.call((getVMBeingRendered() as VM).velements, vnode);
}
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / faux-shadow / traverse.ts View on Github external
(seed, child) => {
                if (resolver === getShadowRootResolver(child)) {
                    ArrayPush.call(seed, child);
                }
                return seed;
            },
            []
github salesforce / lwc / packages / @lwc / engine / src / framework / wiring.ts View on Github external
assert.fail(
                `Internal Error: wire adapters should only be installed in instances with at least one wire declaration.`
            );
        }
    } else {
        const connect = (vm.context.wiredConnecting = []);
        const disconnect = (vm.context.wiredDisconnecting = []);
        for (const fieldNameOrMethod in wire) {
            const descriptor = wire[fieldNameOrMethod];
            const wireDef = WireMetaMap.get(descriptor);
            if (process.env.NODE_ENV !== 'production') {
                assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
            }
            if (!isUndefined(wireDef)) {
                const adapterInstance = createConnector(vm, fieldNameOrMethod, wireDef);
                ArrayPush.call(connect, () => adapterInstance.connect());
                ArrayPush.call(disconnect, () => adapterInstance.disconnect());
            }
        }
    }
}
github salesforce / lwc / packages / @lwc / engine / src / framework / vm.ts View on Github external
export function getErrorComponentStack(startingElement: Element): string {
    const wcStack: string[] = [];
    let elm: Element | null = startingElement;

    do {
        const currentVm = getAssociatedVMIfPresent(elm);
        if (!isUndefined(currentVm)) {
            ArrayPush.call(wcStack, getComponentTag(currentVm));
        }
        elm = getParentOrHostElement(elm);
    } while (!isNull(elm));
    return wcStack.reverse().join('\n\t');
}