How to use the @lwc/shared.getOwnPropertyNames 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 / engine / src / framework / wc.ts View on Github external
if (!isAttributeLocked(this, attrName)) {
                // ignoring changes triggered by the engine itself during:
                // * diffing when public props are attempting to reflect to the DOM
                // * component via `this.setAttribute()`, should never update the prop.
                // Both cases, the the setAttribute call is always wrap by the unlocking
                // of the attribute to be changed
                return;
            }
            // reflect attribute change to the corresponding props when changed
            // from outside.
            this[propName] = newValue;
        }
        // collecting all attribute names from all public props to apply
        // the reflection from attributes to props via attributeChangedCallback.
        static observedAttributes = ArrayMap.call(
            getOwnPropertyNames(props),
            propName => props[propName].attr
        );
    };
}
github salesforce / lwc / packages / @lwc / engine / src / framework / restrictions.ts View on Github external
function getLightningElementPrototypeRestrictionsDescriptors(proto: object): PropertyDescriptorMap {
    if (process.env.NODE_ENV === 'production') {
        // this method should never leak to prod
        throw new ReferenceError();
    }
    const descriptors = {};
    forEach.call(getOwnPropertyNames(globalHTMLProperties), (propName: string) => {
        if (propName in proto) {
            return; // no need to redefine something that we are already exposing
        }
        descriptors[propName] = generateAccessorDescriptor({
            get(this: ComponentInterface) {
                const { error, attribute } = globalHTMLProperties[propName];
                const msg: string[] = [];
                msg.push(`Accessing the global HTML property "${propName}" is disabled.`);
                if (error) {
                    msg.push(error);
                } else if (attribute) {
                    msg.push(`Instead access it via \`this.getAttribute("${attribute}")\`.`);
                }
                logError(msg.join('\n'), getAssociatedVM(this));
            },
            set(this: ComponentInterface) {
github salesforce / lwc / packages / @lwc / engine / src / framework / restrictions.ts View on Github external
`this.template.querySelectorAll() cannot be called during the construction of the custom element for ${vm} because no content has been rendered yet.`
                );
                // Typescript does not like it when you treat the `arguments` object as an array
                // @ts-ignore type-mismatch
                return originalQuerySelectorAll.apply(this, arguments);
            },
        }),
    });
    const BlackListedShadowRootMethods = {
        cloneNode: 0,
        getElementById: 0,
        getSelection: 0,
        elementsFromPoint: 0,
        dispatchEvent: 0,
    };
    forEach.call(getOwnPropertyNames(BlackListedShadowRootMethods), (methodName: string) => {
        const descriptor = generateAccessorDescriptor({
            get() {
                throw new Error(`Disallowed method "${methodName}" in ShadowRoot.`);
            },
        });
        descriptors[methodName] = descriptor;
    });
    return descriptors;
}
github salesforce / lwc / packages / @lwc / engine / src / framework / decorators / register.ts View on Github external
function getWireHash(
    target: ComponentConstructor,
    wire: WireHash | undefined
): WireHash | undefined {
    if (isUndefined(wire) || getOwnPropertyNames(wire).length === 0) {
        return;
    }

    // TODO [#1302]: check that anything in `wire` is correctly defined in the prototype
    return assign(create(null), wire);
}
github salesforce / lwc / packages / @lwc / engine / src / framework / decorators / register.ts View on Github external
function getTrackHash(target: ComponentConstructor, track: TrackDef | undefined): TrackDef {
    if (isUndefined(track) || getOwnPropertyNames(track).length === 0) {
        return EmptyObject;
    }

    // TODO [#1302]: check that anything in `track` is correctly defined in the prototype
    return assign(create(null), track);
}
github salesforce / lwc / packages / @lwc / engine / src / framework / def.ts View on Github external
let {
        connectedCallback,
        disconnectedCallback,
        renderedCallback,
        errorCallback,
        render,
    } = proto;
    const superProto = getCtorProto(Ctor, subclassComponentName);
    const superDef: ComponentDef | null =
        (superProto as any) !== BaseLightningElement
            ? getComponentDef(superProto, subclassComponentName)
            : null;
    const SuperBridge = isNull(superDef) ? BaseBridgeElement : superDef.bridge;
    const bridge = HTMLBridgeElementFactory(
        SuperBridge,
        getOwnPropertyNames(props),
        getOwnPropertyNames(methods)
    );
    if (!isNull(superDef)) {
        props = assign(create(null), superDef.props, props);
        methods = assign(create(null), superDef.methods, methods);
        wire = superDef.wire || wire ? assign(create(null), superDef.wire, wire) : undefined;
        track = assign(create(null), superDef.track, track);
        connectedCallback = connectedCallback || superDef.connectedCallback;
        disconnectedCallback = disconnectedCallback || superDef.disconnectedCallback;
        renderedCallback = renderedCallback || superDef.renderedCallback;
        errorCallback = errorCallback || superDef.errorCallback;
        render = render || superDef.render;
        template = template || superDef.template;
    }
    props = assign(create(null), HTML_PROPS, props);
github salesforce / lwc / packages / @lwc / engine / src / framework / def.ts View on Github external
connectedCallback,
        disconnectedCallback,
        renderedCallback,
        errorCallback,
        render,
    } = proto;
    const superProto = getCtorProto(Ctor, subclassComponentName);
    const superDef: ComponentDef | null =
        (superProto as any) !== BaseLightningElement
            ? getComponentDef(superProto, subclassComponentName)
            : null;
    const SuperBridge = isNull(superDef) ? BaseBridgeElement : superDef.bridge;
    const bridge = HTMLBridgeElementFactory(
        SuperBridge,
        getOwnPropertyNames(props),
        getOwnPropertyNames(methods)
    );
    if (!isNull(superDef)) {
        props = assign(create(null), superDef.props, props);
        methods = assign(create(null), superDef.methods, methods);
        wire = superDef.wire || wire ? assign(create(null), superDef.wire, wire) : undefined;
        track = assign(create(null), superDef.track, track);
        connectedCallback = connectedCallback || superDef.connectedCallback;
        disconnectedCallback = disconnectedCallback || superDef.disconnectedCallback;
        renderedCallback = renderedCallback || superDef.renderedCallback;
        errorCallback = errorCallback || superDef.errorCallback;
        render = render || superDef.render;
        template = template || superDef.template;
    }
    props = assign(create(null), HTML_PROPS, props);

    if (!isUndefined(fields)) {
github salesforce / lwc / packages / @lwc / engine / src / framework / wiring.ts View on Github external
export function installWireAdapters(vm: VM) {
    const {
        def: { wire },
    } = vm;
    if (getOwnPropertyNames(wire).length === 0) {
        if (process.env.NODE_ENV !== 'production') {
            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);