當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript option-t.Option類代碼示例

本文整理匯總了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()));
    }
開發者ID:karen-irc,項目名稱:karen,代碼行數:17,代碼來源:InputBoxView.ts

示例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);
     }
 });
開發者ID:karen-irc,項目名稱:karen,代碼行數:8,代碼來源:SidebarStore.ts

示例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;
        }
    }
開發者ID:karen-irc,項目名稱:karen,代碼行數:43,代碼來源:WindowPresenter.ts

示例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();
    });
開發者ID:karen-irc,項目名稱:karen,代碼行數:39,代碼來源:karen.ts

示例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);
 }));
開發者ID:karen-irc,項目名稱:karen,代碼行數:5,代碼來源:WindowPresenter.ts

示例6: clearLog

    clearLog(): void {
        if (this._currntChannel.isNone) {
            return;
        }

        const channel = this._currntChannel.unwrap();
        this._msgAction.clear(channel.id);
    }
開發者ID:karen-irc,項目名稱:karen,代碼行數:8,代碼來源:InputBoxView.ts

示例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;
    }
開發者ID:karen-irc,項目名稱:karen,代碼行數:18,代碼來源:SidebarStore.ts


注:本文中的option-t.Option類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。