本文整理匯總了TypeScript中rxjs/operators/map.map函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript map函數的具體用法?TypeScript map怎麽用?TypeScript map使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了map函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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}))
)
}
示例2: run
function run() {
if (!command) {
console.log('Welcome to frint-cli!');
console.log('\n');
console.log('These commands are currently available:\n');
return app.getApps$()
.pipe(
map(registeredApps => (
registeredApps
.map(registeredApp => registeredApp.name)
.sort()
)),
take(1),
map(registeredAppNames => (
registeredAppNames
.map(appName => ` - ${appName}`)
.join('\n')
)),
tap(names => console.log(names)),
tap(() => console.log('\n')),
tap(() => console.log('Type `frint help <commandName>` to learn more.'))
)
.subscribe();
}
const commandApp = app.getAppInstance(command);
if (!commandApp) {
return console.log('Command not available.');
}
return commandApp.get<FrintCliProvider>('execute')();
}
示例3: 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)
);
})
);
})
示例4: of
(() => {
of(1, 2, 3, 4)
.pipe(filter(n => n % 2 == 0), map(n => n * n))
.subscribe(n => console.log(n));
const removeEven = () => (source: Observable<number>) => source.pipe(filter(n => n % 2 !== 0));
of(1, 2, 3, 4)
.pipe(removeEven(), map(n => n * n))
.subscribe(n => console.log(n));
}); //();
示例5: ngOnInit
ngOnInit() {
// Capture the session ID if available
this.sessionId = this.route
.queryParamMap
.pipe(
map(params => params.get('sessionId') || 'None')
);
// Capture the fragment if available
this.token = this.route
.fragment
.pipe(
map(fragment => fragment || 'None')
);
}
示例6: 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 > ;
})
);
}
示例7: 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 > ;
})
);
}
示例8: fleshBibUsers
// Flesh the creator and editor fields.
// Handling this separately lets us pull from the cache and
// avoids the requirement that the main bib query use a staff
// (VIEW_USER) auth token.
fleshBibUsers(records: IdlObject[]): Promise<void> {
const search = [];
records.forEach(rec => {
['creator', 'editor'].forEach(field => {
const id = rec[field]();
if (Number.isInteger(id)) {
if (this.userCache[id]) {
rec[field](this.userCache[id]);
} else if (!search.includes(id)) {
search.push(id);
}
}
});
});
if (search.length === 0) {
return Promise.resolve();
}
return this.pcrud.search('au', {id: search})
.pipe(map(user => {
this.userCache[user.id()] = user;
records.forEach(rec => {
if (user.id() === rec.creator()) {
rec.creator(user);
}
if (user.id() === rec.editor()) {
rec.editor(user);
}
});
})).toPromise();
}
示例9: getRole
getRole(): Observable<string> {
return this.authService.onTokenChange()
.pipe(
map((token: NbAuthJWTToken) => {
return token.isValid() ? token.getPayload()['r'] : 'guest';
}),
);
}
示例10: map
const epic9_1: Epic<FluxStandardAction, State, Dependencies, Epic9_Output> = (action$, store, dependencies) =>
action$.pipe(
ofType<FluxStandardAction, Epic9_Input>('NINTH'),
map(({ type, payload }) => ({
type: 'ninth' as 'ninth',
payload: dependencies.func("ninth-" + payload),
}))
);