本文整理匯總了TypeScript中rx.Observable.create方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.create方法的具體用法?TypeScript Observable.create怎麽用?TypeScript Observable.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rx.Observable
的用法示例。
在下文中一共展示了Observable.create方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: join
join(namespace, payload) {
return Observable.create((observable) => {
// connect to socketio endpoint
const socket = socketio.connect(
this.getNamespaceUrl(namespace),
{
path: this.path,
// TODO: remove for allowing fallback?
transports: ['websocket'],
},
);
socket.emit('join', payload);
socket.on('update', observable.onNext.bind(observable));
socket.on('error', observable.onError.bind(observable));
socket.on('reconnect_failed', observable.onError.bind(observable));
// TODO check if the following errors are fatal
// socket.on('reconnect_error', observable.onError.bind(observable));
// socket.on('connect_error', observable.onError.bind(observable));
return () => socket.close();
});
}
示例2: Error
.flatMap((dataSource) => {
return Rx.Observable.create((observer) => {
if (dataSources.length > 1 && !(ds)) {
let error = new Error(`Should have ${fileName} on ${dsDirPath} directory for multiple dataSources.`);
observer.onError(error);
}
let dsConfig = DataSourceConfig.instance;
let source = jsonTemplaterObject(RequireObject(dataSource), dsConfig.config);
let dsKeys = Object.keys(source);
if (ds && (dataSources.length > 1) && (dsKeys && dsKeys.length > 1)) {
let _error = new Error(`File ${ds} should have only one(1) dataSource.`);
observer.onError(_error);
}
dsKeys.forEach((dsKey) => {
app.dataSource(dsKey, source[dsKey]);
if (app.dataSources[dsKey]) {
newDataSources.push(dsKey);
}
});
if ((dataSources.indexOf(dataSource) + 1) === dataSources.length) {
observer.onNext(newDataSources);
observer.onCompleted();
}
});
});
示例3: spawn
export function spawn(cmd: string): Observable<string> {
return Observable.create((observer: Observer<string>) => {
console.log(`---> Spawning ${cmd}`)
const args = cmd.split(' ');
const child = _spawn(args[0], args.slice(1), {
stdio: ['ignore', 'pipe', 'pipe'],
});
child.stdout.on('data', (buffer: Buffer) => {
process.stdout.write(buffer);
observer.onNext(buffer.toString());
});
child.stderr.on('data', (buffer: Buffer) => {
process.stderr.write(buffer);
observer.onNext(buffer.toString());
});
child.on('exit', () => {
observer.onCompleted();
});
return () => {
console.log(`---> Stopping "${cmd}"`);
child.kill();
};
});
}
示例4: onInit
/**
* Initialize/Load/Attached the Model to loopback
* return {Observable} => value = { configs: <object>, modelName: <string>, dataSource: <string> }
*/
onInit(){
let Schema = this[schema];
let Configs = this[configs];
let dataSource = Configs.dataSource;
let schemaCopy = JSON.parse(JSON.stringify(Schema));
let collections = schemaCopy.mongodb.collections;
delete schemaCopy.mongodb;
return Rx.Observable.create((observer) => {
let model = this[app].loopback.createModel(schemaCopy);
model.on('attached', () => {
ModelBinder.bindTo(Configs, model);
MongoDbUtils.createCollection({
app: this[app],
modelName: model.modelName,
dataSource: dataSource,
collections: collections,
schemaCopy: schemaCopy,
configs: Configs
}).subscribe((value) => {
observer.onNext(value);
observer.onCompleted();
});
});
this[app].model(model, {
dataSource: (dataSource) ? dataSource : 'db',
public: true
});
});
}
示例5: loadTumblrData
/**
* Load the tumblr data as an rx operation
*/
loadTumblrData():Observable<Array<PostDetails>> {
return Observable.create<Array<PostDetails>>((observer) => {
tumblrClient.blogPosts('creativedrewy', (err, data) => {
var postData = this.parsePostData(data);
observer.onNext(postData.slice(0, postCount));
});
});
}
示例6: getRoutes
Routes = (route, entityName) => {
return Rx.Observable.create((observer) => {
let routes = [];
if (route) { routes.push(route); }
observer.onNext(routes); observer.onCompleted();
}).flatMap((routes) => {
return getRoutes(routes, entityName)
});
},
示例7: count
export function count(title: string): Rx.Observable<number> {
return Rx.Observable.create((observer: Rx.Observer<number>) => {
db.collection("articles")
.count({ title: { $regex: `\\b${title}\\b`, $options: 'i' } }, (err, count) => {
if (err) { observer.onError(err); }
observer.onNext(count);
observer.onCompleted();
});
});
}
示例8:
.flatMap((modelName) => {
return Rx.Observable.create((observer) => {
observer.onNext({
configs: localConfigs,
modelName: modelName,
dataSources: dataSources
});
observer.onCompleted();
});
});
示例9: find
export function find(title: string): Rx.Observable<IArticle[]> {
return Rx.Observable.create((observer: Rx.Observer<IArticle[]>) => {
db.collection("articles")
.find({ title: { $regex: `\\b${title}\\b`, $options: 'i' } })
.toArray((err, result) => {
if (err) { observer.onError(err); }
observer.onNext(result);
observer.onCompleted();
});
});
}
示例10:
getRoutes = (routes, entityName) => {
return Rx.Observable.create((observer) => {
if (routes.length < 1) {
let entity = Entity.collection.byEntity(entityName);
for (let i = 0; i < entity.routes.length; i++) {
routes.push(RequireObject(entity.routes[i]));
}
}
observer.onNext(routes); observer.onCompleted();
});
};