How to use the link-lib.getPropBestLangRaw function in link-lib

To help you get started, we’ve selected a few link-lib 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 fletcher91 / link-redux / src / hocs / link.ts View on Github external
function getLinkedObjectProperties(
        lrs: LinkReduxLRSType,
        context: LinkRenderContext,
        subjProps: Statement[],
    ): PropertyBoundProps {
        const acc: PropertyBoundProps = {};

        for (const propOpts of Object.values(propMap)) {
            for (const cur of propOpts.label) {
                if (acc[propOpts.name]) {
                    // TODO: Merge
                    continue;
                }

                if (propOpts.limit === 1) {
                    const p = getPropBestLangRaw(
                        lrs.getResourcePropertyRaw(context.subject, cur),
                        (lrs as any).store.langPrefs,
                    );
                    if (p) {
                        acc[propOpts.name] = toReturnType(returnType, p);
                    }
                } else {
                    acc[propOpts.name] = subjProps
                        .filter((s: Statement) => s.predicate.sI === cur.sI)
                        .map(
                            (s: Statement) => toReturnType(returnType, s),
                        ) as Statement[] | SomeTerm[] | string[];
                }
            }
        }
github fletcher91 / link-redux / src / hooks / useLinkedObjectProperties.ts View on Github external
returnType: LinkReturnType,
): PropertyBoundProps {
    const lrs = useLRS();
    const context = useLinkRenderContext();

    const acc: PropertyBoundProps = {};

    for (const propOpts of Object.values(propMap)) {
        for (const cur of propOpts.label) {
            if (acc[propOpts.name]) {
                // TODO: Merge
                continue;
            }

            if (propOpts.limit === 1) {
                const p = getPropBestLangRaw(
                    lrs.getResourcePropertyRaw(context.subject, cur),
                    (lrs as any).store.langPrefs,
                );
                if (p) {
                    acc[propOpts.name] = toReturnType(returnType, p);
                }
            } else {
                acc[propOpts.name] = subjProps
                    .filter((s: Quad) => rdfFactory.id(s.predicate) === rdfFactory.id(cur))
                    .map((s: Quad) => toReturnType(returnType, s)) as Quad[] | SomeTerm[] | string[];
            }
        }
    }

    return acc;
}