當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript pluck.pluck函數代碼示例

本文整理匯總了TypeScript中rxjs/operators/pluck.pluck函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript pluck函數的具體用法?TypeScript pluck怎麽用?TypeScript pluck使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了pluck函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getScrollStream

export function getScrollStream(
    window: Window,
    document: Document,
    socket$: Inputs["socket$"],
    option$: Inputs["option$"]
): Observable<OutgoingSocketEvent> {
    const canSync$ = createTimedBooleanSwitch(
        socket$.pipe(filter(([name]) => name === IncomingSocketNames.Scroll))
    );

    /**
     * If the option 'scrollElementMapping' is provided
     * we cache thw
     * @type {Observable<(Element | null)[]>}
     */
    const elemMap$ = option$.pipe(
        pluck("scrollElementMapping"),
        map((selectors: string[]) =>
            selectors.map(selector => document.querySelector(selector))
        )
    );

    return option$.pipe(
        skip(1), // initial option set before the connection event
        pluck("ghostMode", "scroll"),
        distinctUntilChanged(),
        switchMap(scroll => {
            if (!scroll) return empty();
            return fromEvent(document, "scroll", true).pipe(
                map((e: Event) => e.target),
                withLatestFrom(canSync$, elemMap$),
                filter(([, canSync]) => Boolean(canSync)),
                map(([target, canSync, elemMap]: [any, boolean, any[]]) => {
                    if (target === document) {
                        return ScrollEvent.outgoing(
                            getScrollPosition(window, document),
                            "document",
                            0
                        );
                    }

                    const elems = document.getElementsByTagName(target.tagName);
                    const index = Array.prototype.indexOf.call(
                        elems || [],
                        target
                    );

                    return ScrollEvent.outgoing(
                        getScrollPositionForElement(target),
                        target.tagName,
                        index,
                        elemMap.indexOf(target)
                    );
                })
            );
        })
    );
}
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:58,代碼來源:scroll.listener.ts

示例2: incomingInputsToggles

export function incomingInputsToggles(
    xs: Observable<IncomingPayload>,
    inputs: Inputs
) {
    return xs.pipe(
        withLatestFrom(
            inputs.option$.pipe(pluck("ghostMode", "forms", "toggles")),
            inputs.window$.pipe(pluck("location", "pathname"))
        ),
        filter(([, toggles]) => toggles === true),
        map(([event]) => setElementToggleValue(event))
    );
}
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:13,代碼來源:FormToggleEvent.ts

示例3: incomingKeyupHandler

export function incomingKeyupHandler(
    xs: Observable<IncomingPayload>,
    inputs: Inputs
) {
    return xs.pipe(
        withLatestFrom(
            inputs.option$.pipe(pluck("ghostMode", "forms", "inputs")),
            inputs.window$.pipe(pluck("location", "pathname"))
        ),
        filter(([event, canKeyup, pathname]) => {
            return canKeyup && event.pathname === pathname;
        }),
        map(([event]) => setElementValue(event))
    );
}
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:15,代碼來源:KeyupEvent.ts

示例4: withLatestFrom

 [LogNames.Log]: (xs: Observable<[LogNames, any]>, inputs: Inputs) => {
     return xs.pipe(
         /**
          * access injectNotification from the options stream
          */
         withLatestFrom(
             inputs.logInstance$,
             inputs.option$.pipe(pluck("injectNotification"))
         ),
         /**
          * only accept messages if injectNotification !== console
          */
         filter(
             ([, , injectNotification]) => injectNotification === "console"
         ),
         tap(([event, log]) => {
             switch (event[0]) {
                 case LogNames.Info: {
                     return log.info.apply(log, event[1]);
                 }
                 case LogNames.Debug: {
                     return log.debug.apply(log, event[1]);
                 }
             }
         })
     );
 },
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:27,代碼來源:log.ts

示例5: getFormInputStream

export function getFormInputStream(
    document: Document,
    socket$: Inputs["socket$"],
    option$: Inputs["option$"]
): Observable<OutgoingSocketEvent> {
    const canSync$ = createTimedBooleanSwitch(
        socket$.pipe(filter(([name]) => name === IncomingSocketNames.Keyup))
    );
    return option$.pipe(
        skip(1), // initial option set before the connection event
        pluck("ghostMode", "forms", "inputs"),
        distinctUntilChanged(),
        switchMap(formInputs => {
            if (!formInputs) {
                return empty();
            }
            return fromEvent(document.body, "keyup", true).pipe(
                map((e: Event) => e.target || e.srcElement),
                filter(
                    (target: Element) =>
                        target.tagName === "INPUT" ||
                        target.tagName === "TEXTAREA"
                ),
                withLatestFrom(canSync$),
                filter(([, canSync]) => canSync),
                map(([eventTarget]) => {
                    const target = getElementData(eventTarget);
                    const value = eventTarget.value;

                    return KeyupEvent.outgoing(target, value);
                })
            );
        })
    );
}
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:35,代碼來源:form-inputs.listener.ts

示例6: incomingScrollHandler

export function incomingScrollHandler(
    xs: Observable<IncomingPayload>,
    inputs: Inputs
) {
    return xs.pipe(
        withLatestFrom(
            inputs.option$.pipe(pluck("ghostMode", "scroll")),
            inputs.window$.pipe(pluck("location", "pathname"))
        ),
        filter(([event, canScroll, pathname]) => {
            return canScroll && event.pathname === pathname;
        }),
        map(([event]) => {
            return [EffectNames.BrowserSetScroll, event];
        })
    );
}
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:17,代碼來源:ScrollEvent.ts

示例7: withLatestFrom

export function incomingHandler$(
    xs: Observable<IncomingPayload>,
    inputs: Inputs
) {
    return xs.pipe(
        withLatestFrom(
            inputs.option$.pipe(pluck("ghostMode", "clicks")),
            inputs.window$.pipe(pluck("location", "pathname"))
        ),
        filter(([event, canClick, pathname]) => {
            return canClick && event.pathname === pathname;
        }),
        map(([event]) => {
            return simulateClick(event);
        })
    );
}
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:17,代碼來源:ClickEvent.ts

示例8: incomingBrowserLocation

export function incomingBrowserLocation(
    xs: Observable<IncomingPayload>,
    inputs: Inputs
) {
    return xs.pipe(
        withLatestFrom(inputs.option$.pipe(pluck("ghostMode", "location"))),
        filter(([, canSyncLocation]) => canSyncLocation === true),
        map(([event]) => browserSetLocation(event))
    );
}
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:10,代碼來源:BrowserLocation.ts

示例9: function

 return function(xs, inputs) {
     return xs.pipe(
         withLatestFrom(
             inputs.io$,
             inputs.window$.pipe(pluck("location", "pathname"))
         ),
         tap(([event, io, pathname]) =>
             io.emit(name, { ...event, pathname })
         ),
         ignoreElements()
     );
 };
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:12,代碼來源:socket-messages.ts

示例10: linkReplaceDomEffect

export function linkReplaceDomEffect(
    xs: Observable<LinkReplacePayload>,
    inputs: Inputs
) {
    return xs.pipe(
        withLatestFrom<LinkReplacePayload, any>(
            inputs.option$.pipe(pluck("injectNotification"))
        ),
        filter(([, inject]) => inject),
        map(([incoming, inject]) => {
            const message = `[LinkReplace] ${incoming.basename}`;
            if (inject === "overlay") {
                return Log.overlayInfo(message);
            }
            return Log.consoleInfo(message);
        })
    );
}
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:18,代碼來源:link-replace.dom-effect.ts


注:本文中的rxjs/operators/pluck.pluck函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。