本文整理匯總了TypeScript中rxjs/operators/mergeMap.mergeMap函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript mergeMap函數的具體用法?TypeScript mergeMap怎麽用?TypeScript mergeMap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了mergeMap函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getBibSummary
// Note when multiple IDs are provided, responses are emitted in order
// of receipt, not necessarily in the requested ID order.
getBibSummary(bibIds: number | number[],
orgId?: number, orgDepth?: number): Observable<BibRecordSummary> {
const ids = [].concat(bibIds);
if (ids.length === 0) {
return from([]);
}
return this.pcrud.search('bre', {id: ids},
{ flesh: 1,
flesh_fields: {bre: ['flat_display_entries', 'mattrs']},
select: {bre : this.fetchableBreFields()}
},
{anonymous: true} // skip unneccesary auth
).pipe(mergeMap(bib => {
const summary = new BibRecordSummary(bib, orgId, orgDepth);
summary.net = this.net; // inject
summary.ingest();
return this.getHoldingsSummary(bib.id(), orgId, orgDepth)
.then(holdingsSummary => {
summary.holdingsSummary = holdingsSummary;
return summary;
});
}));
}
示例2: incomingBrowserReload
export function incomingBrowserReload(xs: Observable<any>, inputs: Inputs) {
return xs.pipe(
withLatestFrom(inputs.option$),
filter(([event, options]) => options.codeSync),
mergeMap(reloadBrowserSafe)
);
}
示例3: mergeMap
mergeMap(({ selector, styleNames }) => {
return from(document.querySelectorAll(`[style*=${selector}]`)).pipe(
mergeMap((img: HTMLImageElement) => {
return reloadStyleImages(img.style, styleNames, path, expando);
})
)
})
示例4: function
return function(handlers$, inputStream$) {
return inputStream$.pipe(
groupBy(([keyName]) => {
return keyName;
}),
withLatestFrom(handlers$),
filter(([x, handlers]) => {
return typeof handlers[x.key] === "function";
}),
mergeMap(([x, handlers]) => {
return handlers[x.key](x.pipe(pluck(String(1))), inputs);
}),
share()
);
};
示例5: fileReloadEffect
export function fileReloadEffect(
xs: Observable<FileReloadEventPayload>,
inputs: Inputs
) {
return xs.pipe(
withLatestFrom(inputs.option$, inputs.document$, inputs.navigator$),
mergeMap(([event, options, document, navigator]) => {
return reload(document, navigator)(event, {
tagNames: options.tagNames,
liveCSS: true,
liveImg: true
});
})
);
}
示例6: reattachImportedRule
function reattachImportedRule({ rule, index, link }, document: Document): Observable<any> {
const parent = rule.parentStyleSheet;
const href = generateCacheBustUrl(rule.href);
const media = rule.media.length ? [].join.call(rule.media, ', ') : '';
const newRule = `@import url("${href}") ${media};`;
// used to detect if reattachImportedRule has been called again on the same rule
rule.__LiveReload_newHref = href;
// WORKAROUND FOR WEBKIT BUG: WebKit resets all styles if we add @import'ed
// stylesheet that hasn't been cached yet. Workaround is to pre-cache the
// stylesheet by temporarily adding it as a LINK tag.
const tempLink = document.createElement("link");
tempLink.rel = 'stylesheet';
tempLink.href = href;
tempLink.__LiveReload_pendingRemoval = true; // exclude from path matching
if (link.parentNode) {
link.parentNode.insertBefore(tempLink, link);
}
return timer(200)
.pipe(
tap(() => {
if (tempLink.parentNode) { tempLink.parentNode.removeChild(tempLink); }
// if another reattachImportedRule call is in progress, abandon this one
if (rule.__LiveReload_newHref !== href) { return; }
parent.insertRule(newRule, index);
parent.deleteRule(index+1);
// save the new rule, so that we can detect another reattachImportedRule call
rule = parent.cssRules[index];
rule.__LiveReload_newHref = href;
})
, mergeMap(() => {
return timer(200).pipe(
tap(() => {
// if another reattachImportedRule call is in progress, abandon this one
if (rule.__LiveReload_newHref !== href) { return; }
parent.insertRule(newRule, index);
return parent.deleteRule(index+1);
})
)
})
);
}
示例7: incomingFileReload
export function incomingFileReload(
xs: Observable<FileReloadEventPayload>,
inputs: Inputs
) {
return xs.pipe(
withLatestFrom(inputs.option$),
filter(([event, options]) => options.codeSync),
mergeMap(([event, options]) => {
if (event.url || !options.injectChanges) {
return reloadBrowserSafe();
}
if (event.basename && event.ext && isBlacklisted(event)) {
return empty();
}
return of(fileReload(event));
})
);
}
示例8: incomingConnection
export function incomingConnection(
xs: Observable<IBrowserSyncOptions>,
inputs: Inputs
) {
return xs.pipe(
withLatestFrom(inputs.option$.pipe(pluck("logPrefix"))),
mergeMap(([x, logPrefix]) => {
const prefix = logPrefix
? `${logPrefix}: `
: '';
return of<any>(
setOptions(x),
Log.overlayInfo(`${prefix}connected`)
);
})
);
}
示例9: reloadImages
function reloadImages(path, document): Observable<any> {
const expando = generateUniqueString(Date.now());
return merge(
from([].slice.call(document.images))
.pipe(
filter((img: HTMLImageElement) => pathsMatch(path, pathFromUrl(img.src)))
, map((img: HTMLImageElement) => {
const payload = {
target: img,
prop: 'src',
value: generateCacheBustUrl(img.src, expando),
pathname: getLocation(img.src).pathname
};
return propSet(payload);
})
),
from(IMAGE_STYLES)
.pipe(
mergeMap(({ selector, styleNames }) => {
return from(document.querySelectorAll(`[style*=${selector}]`)).pipe(
mergeMap((img: HTMLImageElement) => {
return reloadStyleImages(img.style, styleNames, path, expando);
})
)
})
)
);
// if (document.styleSheets) {
// return [].slice.call(document.styleSheets)
// .map((styleSheet) => {
// return reloadStylesheetImages(styleSheet, path, expando);
// });
// }
}
示例10: reattachStylesheetLink
function reattachStylesheetLink(link: HTMLLinkElement, document: Document, navigator: Navigator): Observable<any> {
// ignore LINKs that will be removed by LR soon
let clone;
if (link.__LiveReload_pendingRemoval) {
return empty();
}
link.__LiveReload_pendingRemoval = true;
if (link.tagName === 'STYLE') {
// prefixfree
clone = document.createElement('link');
clone.rel = 'stylesheet';
clone.media = link.media;
clone.disabled = link.disabled;
} else {
clone = link.cloneNode(false);
}
const prevHref = link.href;
const nextHref = generateCacheBustUrl(linkHref(link));
clone.href = nextHref;
const {pathname} = getLocation(nextHref);
const basename = pathname.split('/').slice(-1)[0];
// insert the new LINK before the old one
const parent = link.parentNode;
if (parent.lastChild === link) {
parent.appendChild(clone);
} else {
parent.insertBefore(clone, link.nextSibling);
}
let additionalWaitingTime;
if (/AppleWebKit/.test(navigator.userAgent)) {
additionalWaitingTime = 5;
} else {
additionalWaitingTime = 200;
}
return Observable.create(obs => {
clone.onload = () => {
obs.next(true);
obs.complete()
};
})
.pipe(
mergeMap(() => {
return timer(additionalWaitingTime)
.pipe(
tap(() => {
if (link && !link.parentNode) {
return;
}
link.parentNode.removeChild(link);
clone.onreadystatechange = null;
})
, mapTo(linkReplace({target: clone, nextHref, prevHref, pathname, basename}))
)
})
)
}