本文整理汇总了TypeScript中@reactivex/rxjs.Observable类的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable类的具体用法?TypeScript Observable怎么用?TypeScript Observable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Observable类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
(data) => {
return Rx.Observable.of({
target: target,
data: data,
fileName: file.name
});
}
示例2: Post
() => {
console.log('Users are saved!');
const postPromises = posts.map(post => {
const {userId, title, body} = post;
return User.findOne({id: userId})
.then(user => {
const newPost = new Post({title, body, _creator: user._id});
return newPost.save();
})
.then(newPost => {
const postCommentsIndex = i + 10;
for (i; i < postCommentsIndex && i < last; i++) {
const {body, email} = comments[i];
let newComment = new Comment({_post: newPost._id, body, email});
return newComment.save();
}
});
});
let counter = 0;
Rx.Observable
.forkJoin(postPromises)
.subscribe(
() => null,
(err) => console.log(`Err: ${err}`),
() => {
console.log('DB population is completed!');
process.exit();
}
);
}
示例3: to
to(exchange: string, iO: Observable<any>): Subscription<any> {
let channel, conn, cachedItems = [];
let queue = uuid.v4();
connect(this.config.connString)
.then(c => conn = c && c.createChannel())
.then(c => {
channel = c;
channel.assertExchange(exchange, 'fanout');
cachedItems.forEach(item => {
channel.publish(exchange, '', new Buffer(item));
});
})
.catch(err => { throw err; });
return iO
.subscribe(
msg => {
if (!channel) {
return cachedItems.push(msg);
}
channel.publish(exchange, '', new Buffer(msg));
},
err => console.error(`rabbitSink err, queue: ${queue}`, err),
() => {
if (conn) {
channel.publish(exchange, '', new Buffer('__done'));
conn.close()
}
}
);
}
示例4: init
function init(state_: string, current_: number) {
console.log('new');
return Observable.fromPromise(new Promise((resolve, reject) => {
setTimeout(() => {
resolve('init success');
}, 2000);
}));
}
示例5:
this.action$ = this.inStream$.flatMap(v => {
if (v instanceof Rx.Observable) {
return v;
} else {
return Rx.Observable.from([v]);
}
}).share();
示例6:
.mergeMap(() => {
return Rx.Observable.fromEvent($('.more'), 'click')
.do((e)=>{
const target = $(e.currentTarget)
console.log(target.text(), path)
location.href=(path + 'more/' + target.text())
})
})
示例7: newValidationStatus
(resp) => {
const ans = newValidationStatus();
ans.currPasswd = resp.fields.curr_passwd;
ans.newPasswd = resp.fields.new_passwd;
ans.newPasswd2 = resp.fields.new_passwd2;
ans.messages = resp.messages.splice(0);
return Rx.Observable.of(ans);
}
示例8: to
to(channelName: string, iO: Observable<any>): Subscription<any> {
this.initChannel(channelName);
return iO.subscribe(
item => this.channels[channelName].forEach(fn => fn(item)),
err => { throw err; },
() => this.channels[channelName].forEach(fn => fn('__done'))
);
}
示例9:
subs.subscribe(({connection, message:{symbol}}:any) => {
const source = Observable.interval(500).map(() => ({
symbol,
price: Math.random() * 100,
timestamp: Date.now()
}));
connection.streams = connection.streams || {};
connection.streams[symbol] = source.subscribe(connection);
});
示例10: Error
(data) => {
console.log('data: ', data);
if (data.lastpage && data.Items.length === 0) {
throw new Error(this.layoutModel.translate('wordlist__page_not_found_err'));
}
this.data = this.importData(data.Items);
this.isLastPage = !!data.lastpage;
return Rx.Observable.of(data);
}