本文整理汇总了TypeScript中rxjs/operators/filter.filter函数的典型用法代码示例。如果您正苦于以下问题:TypeScript filter函数的具体用法?TypeScript filter怎么用?TypeScript filter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了filter函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: reloadStyleImages
function reloadStyleImages(style, styleNames: string[], path, expando): Observable<any> {
return from(styleNames).pipe(
filter(styleName => typeof style[styleName] === 'string')
, map((styleName: string) => {
let pathName;
const value = style[styleName];
const newValue = value.replace(new RegExp(`\\burl\\s*\\(([^)]*)\\)`), (match, src) => {
let _src = src;
if (src[0] === '"' && src[src.length-1] === '"') {
_src = src.slice(1, -1);
}
pathName = getLocation(_src).pathname;
if (pathsMatch(path, pathFromUrl(_src))) {
return `url(${generateCacheBustUrl(_src, expando)})`;
} else {
return match;
}
});
return [
style,
styleName,
value,
newValue,
pathName
];
})
, filter(([style, styleName, value, newValue]) => newValue !== value)
, map(([style, styleName, value, newValue, pathName]) => styleSet({style, styleName, value, newValue, pathName}))
)
}
开发者ID:BrowserSync,项目名称:browser-sync,代码行数:31,代码来源:Reloader.ts
示例2: 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
示例3: withLatestFrom
[Overlay.Info]: (xs: Observable<[LogNames, any]>, inputs: Inputs) => {
return xs.pipe(
withLatestFrom(
inputs.option$,
inputs.notifyElement$,
inputs.document$
),
/**
* Reject all notifications if notify: false
*/
filter(([, options]) => Boolean(options.notify)),
/**
* Set the HTML of the notify element
*/
tap(([event, options, element, document]) => {
element.innerHTML = event[0];
element.style.display = "block";
document.body.appendChild(element);
}),
/**
* Now remove the element after the given timeout
*/
switchMap(([event, options, element, document]) => {
return timer(event[1] || 2000).pipe(
tap(() => {
element.style.display = "none";
if (element.parentNode) {
document.body.removeChild(element);
}
})
);
})
);
}
开发者ID:BrowserSync,项目名称:browser-sync,代码行数:34,代码来源:log.ts
示例4: login
login(params: any): Observable<any> {
var __headers = new HttpHeaders({
'Content-Type': 'application/json'
});
var __body = {
EmailAddress: params.username,
Password:(params.password),
};
let req = new HttpRequest < any > (
'POST',
this.rootUrl + `/account/token`,
__body, {
headers: __headers
});
return this.http.request < any > (req).pipe(
filter(_r => _r instanceof HttpResponse),
map(_r => {
let _resp = _r as HttpResponse < any > ;
let _body = _resp.body;
if (_resp.ok) {
localStorage.clear();
Object.keys(_body).map(key => localStorage.setItem(key, _body[key]));
} else {
localStorage.clear();
}
return _resp.clone({
body: _body
}) as HttpResponse < any > ;
})
);
}
开发者ID:sgbangale,项目名称:AngularApp,代码行数:35,代码来源:account.service.ts
示例5: request
request(params: any,request_type:string): Observable < any > {
var __headers = new HttpHeaders({
'Content-Type': 'application/json'
});
var __body = {
"request_data": params
};
let req = new HttpRequest < any > (
'POST',
this.rootUrl + `/request?request_type=`+request_type,
__body, {
headers: __headers
});
return this.http.request < any > (req).pipe(
filter(_r => _r instanceof HttpResponse),
map(_r => {
let _resp = _r as HttpResponse < any > ;
let _body = _resp.body;
return _resp.clone({
body: _body
}) as HttpResponse < any > ;
})
);
}
开发者ID:sgbangale,项目名称:AngularApp,代码行数:26,代码来源:request.service.ts
示例6: incomingBrowserReload
export function incomingBrowserReload(xs: Observable<any>, inputs: Inputs) {
return xs.pipe(
withLatestFrom(inputs.option$),
filter(([event, options]) => options.codeSync),
mergeMap(reloadBrowserSafe)
);
}
开发者ID:BrowserSync,项目名称:browser-sync,代码行数:7,代码来源:BrowserReload.ts
示例7: switchMap
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,代码行数:30,代码来源:scroll.listener.ts
示例8: 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
示例9: 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
注:本文中的rxjs/operators/filter.filter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论