本文整理汇总了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}))
)
})
)
}