本文整理汇总了TypeScript中rxjs.from函数的典型用法代码示例。如果您正苦于以下问题:TypeScript from函数的具体用法?TypeScript from怎么用?TypeScript from使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了from函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('`setup` registers plugin config schema in config service', async () => {
const configSchema = schema.string();
jest.spyOn(configService, 'setSchema').mockImplementation(() => Promise.resolve());
jest.doMock(
join('path-with-schema', 'server'),
() => ({
config: {
schema: configSchema,
},
}),
{
virtual: true,
}
);
mockDiscover.mockReturnValue({
error$: from([]),
plugin$: from([
new PluginWrapper(
'path-with-schema',
{
id: 'some-id',
version: 'some-version',
configPath: 'path',
kibanaVersion: '7.0.0',
requiredPlugins: [],
optionalPlugins: [],
server: true,
ui: true,
},
{ logger } as any
),
]),
});
await pluginsService.setup(setupDeps);
expect(configService.setSchema).toBeCalledWith('path', configSchema);
});
示例2: from
/**
* @param url
* @param data
* @param config
*/
post<T, U = string>(url: string, data?: any, config: AxiosRequestConfig = {}): Observable<IResult<T, U>> {
return from(axios.post(url, data, config))
.pipe(
map(response => response.data),
catchError((error: AxiosResponse | undefined) => {
console.log(error);
if (error === undefined) {
return message.error('请求出错');
}
this.error$ = of(error);
this.handleError();
return this.error$;
})
);
}
示例3: addProcessInstanceComment
/**
* Adds a comment to a process instance.
* @param processInstanceId ID of the target process instance
* @param message Text for the comment
* @returns Details of the comment added
*/
addProcessInstanceComment(processInstanceId: string, message: string): Observable<CommentModel> {
return from(
this.apiService.getInstance().activiti.commentsApi.addProcessInstanceComment({ message: message }, processInstanceId)
).pipe(
map((response: CommentModel) => {
return new CommentModel({
id: response.id,
message: response.message,
created: response.created,
createdBy: response.createdBy
});
}),
catchError((err: any) => this.handleError(err))
);
}
示例4: from
export function wrapIntoObservable<T>(value: T | NgModuleFactory<T>| Promise<T>| Observable<T>):
Observable<T> {
if (isObservable(value)) {
return value;
}
if (isPromise(value)) {
// Use `Promise.resolve()` to wrap promise-like instances.
// Required ie when a Resolver returns a AngularJS `$q` promise to correctly trigger the
// change detection.
return from(Promise.resolve(value));
}
return of (value as T);
}
示例5: it
it('should map values to resolved promises and concatenate', (done) => {
const source = from([4, 3, 2, 1]);
const project = (value: number, index: number) => Observable.from(Promise.resolve(value + index));
const results: number[] = [];
source.concatMap(project).subscribe(
(x) => {
results.push(x);
}, (err) => {
done(new Error('Subscriber error handler not supposed to be called.'));
}, () => {
expect(results).to.deep.equal([4, 4, 4, 4]);
done();
});
});
示例6: getProcessInstances
/**
* Gets process instances for a filter and optionally a process definition.
* @param requestNode Filter for instances
* @param processDefinitionKey Limits returned instances to a process definition
* @returns List of process instances
*/
getProcessInstances(requestNode: ProcessFilterParamRepresentationModel, processDefinitionKey?: string): Observable<ProcessListModel> {
return from(this.alfrescoApiService.getInstance().activiti.processApi.getProcessInstances(requestNode))
.pipe(
map((res: any) => {
if (processDefinitionKey) {
const filtered = res.data.filter((process) => process.processDefinitionKey === processDefinitionKey);
res.data = filtered;
return res;
} else {
return res;
}
}),
catchError((err) => this.handleProcessError(err))
);
}
示例7: mergeMap
mergeMap(() => {
const state = state$.value;
const contentRef$ = from(
state.core.entities.contents.byRef
.filter(
// Don't bother with non-file and non-notebook types for saving
// (no dummy or directory)
content => content.type === "file" || content.type === "notebook"
)
.keys()
);
return contentRef$;
}),
示例8: getNpmPackageJson
export function getNpmPackageJson(
packageName: string,
logger: logging.LoggerApi,
options?: {
registryUrl?: string;
usingYarn?: boolean;
verbose?: boolean;
},
): Observable<Partial<NpmRepositoryPackageJson>> {
const cachedResponse = npmPackageJsonCache.get(packageName);
if (cachedResponse) {
return cachedResponse;
}
if (!npmrc) {
try {
npmrc = readOptions(logger, false, options && options.verbose);
} catch { }
if (options && options.usingYarn) {
try {
npmrc = { ...npmrc, ...readOptions(logger, true, options && options.verbose) };
} catch { }
}
}
const resultPromise: Promise<NpmRepositoryPackageJson> = pacote.packument(
packageName,
{
'full-metadata': true,
...npmrc,
...(options && options.registryUrl ? { registry: options.registryUrl } : {}),
},
);
// TODO: find some way to test this
const response = from(resultPromise).pipe(
shareReplay(),
catchError(err => {
logger.warn(err.message || err);
return EMPTY;
}),
);
npmPackageJsonCache.set(packageName, response);
return response;
}
示例9: findGroupsByName
/**
* Finds groups filtered by name.
* @param searchParams Object containing the name filter string
* @returns List of group information
*/
findGroupsByName(searchParams: GroupSearchParam): Observable<any> {
if (searchParams.name === '') {
return of([]);
}
const url = this.getGroupsApi();
const httpMethod = 'GET', pathParams = {}, queryParams = {search: searchParams.name}, bodyParam = {}, headerParams = {},
formParams = {}, contentTypes = ['application/json'], accepts = ['application/json'];
return (from(this.apiService.getInstance().oauth2Auth.callCustomApi(
url, httpMethod, pathParams, queryParams,
headerParams, formParams, bodyParam,
contentTypes, accepts, Object, null, null)
)).pipe(
catchError((err) => this.handleError(err))
);
}
示例10: switchMap
switchMap(user => {
if (user) {
return from(user.getIdToken())
.pipe(
switchMap((token) => {
return next.handle(req.clone({
setHeaders: {
Authorization: token
}
}));
})
);
} else {
return next.handle(req);
}
})