本文整理匯總了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);
}