How to use the @lwc/shared.isTrue 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 / features / src / runtime.ts View on Github external
function setFeatureFlag(name: string, value: FeatureFlagValue) {
    const isBoolean = isTrue(value) || isFalse(value);
    if (!isBoolean) {
        const message = `Invalid ${typeof value} value specified for the "${name}" flag. Runtime feature flags can only be set to a boolean value.`;
        if (process.env.NODE_ENV === 'production') {
            // eslint-disable-next-line no-console
            console.error(message);
        } else {
            throw new TypeError(message);
        }
    }
    if (!isUndefined(features[name])) {
        runtimeFlags[name] = value;
    } else {
        // eslint-disable-next-line no-console
        console.warn(
            `LWC feature flag "${name}" is undefined. Possible reasons are that 1) it was misspelled or 2) it was removed from the @lwc/features package.`
        );
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / polyfills / window-event-target / polyfill.ts View on Github external
function isQualifyingEventTarget(currentTarget: Window, evt: Event): boolean {
    const originalTarget = eventTargetGetter.call(evt);
    if (originalTarget === currentTarget) {
        // dispatched on the window directly
        return true;
    }
    const { composed } = evt;
    // if the event reaches the window by propagation, it is because it is bubbling,
    // in which the the only it really depends on the composed value
    return isTrue(composed) || !isNodeShadowed(originalTarget as Node);
}
github salesforce / lwc / packages / @lwc / engine / src / framework / hooks.ts View on Github external
export function createViewModelHook(vnode: VCustomElement) {
    const elm = vnode.elm as HTMLElement;
    if (!isUndefined(getAssociatedVMIfPresent(elm))) {
        // There is a possibility that a custom element is registered under tagName,
        // in which case, the initialization is already carry on, and there is nothing else
        // to do here since this hook is called right after invoking `document.createElement`.
        return;
    }
    const { mode, ctor, owner } = vnode;
    const def = getComponentDef(ctor);
    setElementProto(elm, def);
    if (isTrue(useSyntheticShadow)) {
        const { shadowAttribute } = owner.context;
        // when running in synthetic shadow mode, we need to set the shadowToken value
        // into each element from the template, so they can be styled accordingly.
        setElementShadowToken(elm, shadowAttribute);
    }
    createVM(elm, ctor, {
        mode,
        owner,
    });
    if (process.env.NODE_ENV !== 'production') {
        assert.isTrue(
            isArray(vnode.children),
            `Invalid vnode for a custom element, it must have children defined.`
        );
    }
    if (process.env.NODE_ENV !== 'production') {
github salesforce / lwc / packages / @lwc / engine / src / framework / hooks.ts View on Github external
export function fallbackElmHook(vnode: VElement) {
    const { owner } = vnode;
    const elm = vnode.elm as HTMLElement;
    if (isTrue(useSyntheticShadow)) {
        const {
            data: { context },
        } = vnode;
        const { shadowAttribute } = owner.context;
        if (
            !isUndefined(context) &&
            !isUndefined(context.lwc) &&
            context.lwc.dom === LWCDOMMode.manual
        ) {
            // this element will now accept any manual content inserted into it
            observeElementChildNodes(elm);
        }
        // when running in synthetic shadow mode, we need to set the shadowToken value
        // into each element from the template, so they can be styled accordingly.
        setElementShadowToken(elm, shadowAttribute);
    }
github salesforce / lwc / packages / @lwc / node-reactions / src / core / reactions.ts View on Github external
export function isRegisteredNode(node: Node): boolean {
    return isTrue(getHiddenField(node, RegisteredFlag));
}
github salesforce / lwc / packages / @lwc / engine / src / framework / vm.ts View on Github external
function rehydrate(vm: VM) {
    if (process.env.NODE_ENV !== 'production') {
        assert.isTrue(
            vm.elm instanceof HTMLElement,
            `rehydration can only happen after ${vm} was patched the first time.`
        );
    }
    if (isTrue(vm.isDirty)) {
        const children = renderComponent(vm);
        patchShadowRoot(vm, children);
    }
}
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / faux-shadow / portal.ts View on Github external
set(this: Element, v: boolean) {
        this[DomManualPrivateKey] = v;
        if (isTrue(v)) {
            markElementAsPortal(this);
        }
    },
    get() {
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / faux-shadow / shadow-root.ts View on Github external
value(this: SyntheticShadowRootInterface, options?: GetRootNodeOptions): Node {
            return !isUndefined(options) && isTrue(options.composed)
                ? getHost(this).getRootNode(options)
                : this;
        },
    },