本文整理汇总了TypeScript中option-t.Option类的典型用法代码示例。如果您正苦于以下问题:TypeScript Option类的具体用法?TypeScript Option怎么用?TypeScript Option使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Option类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _createSuggestion
private _createSuggestion(value: string): Array<string> {
const candidate: Array<string> = ([] as Array<string>).concat(words);
const users: Option<Array<User>> = this._currntChannel.map(function (channel) {
return channel.userList();
});
if (users.isSome) {
for (const user of users.unwrap()) {
const n = user.nickname;
candidate.push(n.toLowerCase());
}
}
return candidate.filter(function (word: string, item: string) {
return item.indexOf(word) === 0;
}.bind(null, value.toLowerCase()));
}
示例2:
domain.getCurrentTab().map((v) => v.channelId).do((channelId: Option<ChannelId>) => {
this._currentId = channelId;
if (channelId.isSome) {
const id = channelId.unwrap();
this._notableChannelSet.delete(id);
this._unreadCount.set(id, 0);
}
});
示例3: handleShortcut
handleShortcut(event: KeyboardEvent, key: string): void {
const channelList: Array<Channel> = this._domain.networkSet.getChannelList();
// tslint:disable-next-line:no-non-null-assertion
const currentIndex: Option<ChannelId> = this._domain.currentTab!.channelId.map(function (currentId: ChannelId): number {
const result = channelList.findIndex(function (channel: Channel) {
return channel.id === currentId;
});
if (result === undefined) {
throw new Error('should not be undefined');
}
else {
return result;
}
});
if (currentIndex.isNone) {
return;
}
const index = currentIndex.unwrap();
const length = channelList.length;
switch (key) {
case 'ArrowUp':
{
// Loop
const target = (length + (index - 1 + length)) % length;
const id = channelList[target].id;
event.preventDefault();
this._uiAction.selectChannel(id);
}
break;
case 'ArrowDown':
{
// Loop
const target = (length + (index + 1 + length)) % length;
const id = channelList[target].id;
event.preventDefault();
this._uiAction.selectChannel(id);
}
break;
}
}
示例4: onSubmit
socket.auth().subscribe(function (_: any) { // tslint:disable-line:no-any
const body: HTMLElement = window.document.body;
const login = document.getElementById('sign-in');
if (login === null) {
intent.app.reload();
return;
}
// @ts-ignore
Array.from(login.querySelectorAll('.btn')).forEach(function (element: HTMLInputElement) {
element.disabled = false;
});
const token: Option<string> = auth.getToken();
if (token.isSome) {
auth.removeToken();
socket.emit('auth', { token: token.unwrap() });
}
if (body.classList.contains('signed-out')) {
const error = login.querySelector('.error') as HTMLElement;
error.style.display = '';
// tslint:disable-next-line:no-non-null-assertion
const form = login.querySelector('.container')!;
form.addEventListener('submit', function onSubmit() {
form.removeEventListener('submit', onSubmit);
error.style.display = 'none';
});
}
if (token.isNone) {
body.classList.add('signed-out');
}
const input = login.querySelector('input[name=\'user\']') as HTMLInputElement;
if (input.value === '') {
input.value = auth.getUser().unwrapOr('');
}
if (token.isSome) {
return;
}
uiAction.showSignIn();
});
示例5:
this._disposer.add(domain.getSelectedChannel().subscribe((id: ChannelId) => {
const current: Option<Channel> = domain.networkSet.getChannelById(id);
const title = current.unwrap().name;
this.onCurrentTabChanged(title);
}));
示例6: clearLog
clearLog(): void {
if (this._currntChannel.isNone) {
return;
}
const channel = this._currntChannel.unwrap();
this._msgAction.clear(channel.id);
}
示例7: _updateUnreadCount
private _updateUnreadCount(channelId: ChannelId): boolean {
const targetIsCurrent: boolean = this._currentId.mapOr(false, function(id){
return id === channelId;
});
if (targetIsCurrent) {
return false;
}
let current: number | undefined = this._unreadCount.get(channelId);
if (current === undefined) {
this._unreadCount.set(channelId, 0);
current = 0;
}
const latest = current + 1;
this._unreadCount.set(channelId, latest);
return true;
}