本文整理匯總了TypeScript中rx.Observable.from方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.from方法的具體用法?TypeScript Observable.from怎麽用?TypeScript Observable.from使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rx.Observable
的用法示例。
在下文中一共展示了Observable.from方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
let main = () => ({
bot: $.from([
$.just(sendContact(
{ chat_id: GROUP_ID, phone_number: '+42470', first_name: 'Telegram' },
{}))
])
})
示例2: editMessageReplyMarkup
let main = ({ bot }: Sources) => ({
bot: $.from([
bot.events('message')
.do(() => bot.dispose())
.map(reply({
text: 'Message with reply_markup',
reply_markup: {
inline_keyboard: [
[{ text: '1', callback_data: 'one' }],
[{ text: '2', callback_data: 'two' }],
[{ text: '3', callback_data: 'three' }]
]
}
})),
bot.responses
.take(1)
.map(message => editMessageReplyMarkup(
{
reply_markup: {
inline_keyboard: [
[{ text: '4', callback_data: 'four' }],
[{ text: '5', callback_data: 'five' }],
[{ text: '6', callback_data: 'six' }]
]
}
},
{ message }))
])
})
示例3: it
it("should apply map function to messages and forward to observable", (done) => {
const server = dgram.createSocket("udp4");
const client = dgram.createSocket("udp4");
server.bind(SERVER_PORT, SERVER_HOST);
const observable = rxUdp.observableFromSocket<string>(
b => b.toString("utf8"), server);
const valuesSent = [ "hello", "world", "!" ];
const valuesReceived = [];
Rx.Observable.from(valuesSent).flatMap(value => {
return Rx.Observable.fromNodeCallback<string, number>(
(message: string, callback: (err: Error, result: number) => void) => {
const buffer = new Buffer(message, "utf8");
client.send(buffer, 0, buffer.byteLength, SERVER_PORT, SERVER_HOST, callback);
})(value);
}).subscribeOnCompleted(() => {
setTimeout(() => {
server.close();
}, 20);
});
observable.forEach(s => valuesReceived.push(s));
observable.subscribeOnCompleted(() => {
// order is not important, reception is
expect(valuesReceived).to.have.length(3);
expect(valuesSent).to.include.members(valuesReceived);
done();
});
});
示例4: matchStream
let main = (s: Sources) => ({
bot: $.from([
matchStream(s.bot.events('message').filter(entityIs('bot_command')), plugins, s)
.pluck('bot')
.mergeAll()
])
})
示例5: toSpinalCase
DataSource = (app, dsDirPath, dataSources) => {
let modelName = toSpinalCase(GetModelSchema(dsDirPath).name);
let fileName = `${modelName}-datasources.json`;
let ds = getParentDataSource(fileName, dataSources);
let newDataSources = [];
return Rx.Observable.from(dataSources)
.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();
}
});
});
},