Skip to content
This repository was archived by the owner on Dec 28, 2018. It is now read-only.

Commit 9660b36

Browse files
fix(typescript): fix compile error
1 parent ff02383 commit 9660b36

19 files changed

+62
-99
lines changed

src/client/rize/adapter/NotificationService.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ function requestPermittion(): Rx.Observable<boolean> {
8080
}
8181

8282
function showNotification(topic: NotifedTopic): Rx.Observable<void> {
83-
let notification: Notification = new (window as any).Notification(topic.title, {
83+
let notification: Notification | void = new (window as any).Notification(topic.title, {
8484
body: topic.body,
8585
icon: topic.icon,
8686
});
8787
const timeout = Rx.Observable.empty<void>().delay(5 * 1000);
88-
const click = Rx.Observable.fromEvent<void>(notification, 'click').take(1);
88+
const click = Rx.Observable.fromEvent<void>(notification!, 'click').take(1);
8989
const close: Rx.Observable<void> = click.race(timeout).do(function(){
9090
notification.close();
91-
notification = null;
91+
notification = undefined;
9292
});
9393
return close.share();
9494
}

src/client/rize/rize.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class RizeClient {
5050
console.log(data.value);
5151
});
5252

53-
const view = React.createElement(RizeAppView, null);
53+
const view = React.createElement(RizeAppView, undefined);
5454
const mountpoint = document.getElementById('js-mountpoint-app');
5555
ReactDOM.render(view, mountpoint);
5656
}

src/client/script/adapter/AudioDriver.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525

2626
export class AudioDriver {
27-
_audio: HTMLAudioElement;
27+
private _audio: HTMLAudioElement | void;
2828

2929
constructor(path: string) {
3030
const audio = new Audio();
@@ -34,6 +34,10 @@ export class AudioDriver {
3434
this._audio = audio;
3535
}
3636

37+
destroy(): void {
38+
this._audio = undefined;
39+
}
40+
3741
play(): void {
3842
this._audio.play();
3943
}

src/client/script/domain/Channel.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export class Channel {
3636
private _userList: Array<User>;
3737
private _unread: number;
3838
private _messageBuffer: Array<Message>;
39-
private _network: Network;
39+
private _network: Network | void;
4040

41-
constructor(raw: any, network: Network = null) {
41+
constructor(raw: any, network: Network | void = undefined) {
4242
this.id = raw.id;
4343

4444
this.name = raw.name;
@@ -55,13 +55,10 @@ export class Channel {
5555

5656
this._unread = raw.unread;
5757

58-
let messages: Array<Message> = null;
58+
let messages: Array<Message> = [];
5959
if (Array.isArray(raw.messages)) {
6060
messages = raw.messages;
6161
}
62-
else {
63-
messages = [];
64-
}
6562

6663
this._messageBuffer = messages;
6764
this._network = network;
@@ -79,7 +76,7 @@ export class Channel {
7976
return this._userList;
8077
}
8178

82-
getNetwork(): Network {
79+
getNetwork(): Network | void {
8380
return this._network;
8481
}
8582

src/client/script/domain/ChannelDomain.ts

-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ export class ChannelDomain {
123123

124124
dispose(): void {
125125
this._ignitionDisposable.unsubscribe();
126-
this._notableDispatcher = null;
127126
}
128127

129128
getId(): ChannelId {

src/client/script/domain/DomainState.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ export class SelectedTab {
6464
export class DomainState {
6565

6666
private _networkSet: NetworkSetDomain;
67-
private _latestCurrentTab: SelectedTab;
67+
private _latestCurrentTab: SelectedTab | void;
6868
private _currentTab: Rx.Observable<SelectedTab>;
6969
private _notifiableMessage: Rx.Observable<RecievedMessage>;
7070

7171
constructor(gateway: MessageGateway) {
7272
this._networkSet = new NetworkSetDomain(gateway);
73-
this._latestCurrentTab = null;
73+
this._latestCurrentTab = undefined;
7474

7575
// In most of case, a rendering operation is depend on the source of `selectTab()`.
7676
// So this observable should be on the next event loop.
@@ -79,18 +79,18 @@ export class DomainState {
7979
}).observeOn(Rx.Scheduler.asap).share();
8080

8181
this._notifiableMessage = this._networkSet.recievedNotifiableMessage()
82-
.withLatestFrom(this._currentTab, function (data, current): RecievedMessage {
82+
.withLatestFrom(this._currentTab, function (data, current): RecievedMessage | void {
8383
const isSameChannel: boolean = current.channelId.mapOr(false, function (current: ChannelId) {
8484
return data.channelId === current;
8585
});
8686
if (isSameChannel) {
87-
return null;
87+
return undefined;
8888
}
8989

9090
return data;
9191
}).filter(function (data) {
92-
return data !== null;
93-
}).share();
92+
return data !== undefined;
93+
}).map((data) => data!).share();
9494
}
9595

9696
/**
@@ -100,7 +100,7 @@ export class DomainState {
100100
return this._networkSet.legacy;
101101
}
102102

103-
get currentTab(): SelectedTab {
103+
get currentTab(): SelectedTab | void {
104104
return this._latestCurrentTab;
105105
}
106106

@@ -155,7 +155,7 @@ function selectTab(gateway: MessageGateway, intent: UIActionDispatcher, set: Net
155155
});
156156

157157
const removedNetwork = set.removedNetwork().withLatestFrom(set.getNetworkList(), function(_, list) {
158-
let tab: SelectedTab = null;
158+
let tab: SelectedTab;
159159
if (list.length === 0) {
160160
tab = new SelectedTab(CurrentTabType.SETTING, 'connect');
161161
}
@@ -183,7 +183,7 @@ function selectTab(gateway: MessageGateway, intent: UIActionDispatcher, set: Net
183183
});
184184

185185
const initial = set.initialState().map(function(data){
186-
let tab: SelectedTab = null;
186+
let tab: SelectedTab;
187187

188188
const idIsSetting = data.active.mapOr(true, function(id){
189189
return (typeof id !== 'number');

src/client/script/domain/NetworkDomain.ts

-8
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,7 @@ export class NetworkDomain {
126126
}
127127

128128
dispose(): void {
129-
this._data = null;
130-
this._nickname = null;
131-
this._joinedChannel = null;
132-
this._partedChannel = null;
133-
134-
this._notableMsgDispatcher = null;
135-
136129
this._subscribed.unsubscribe();
137-
this._subscribed = null;
138130
}
139131

140132
getId(): number {

src/client/script/intent/action/ConnectionActionCreator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class ConnectionActionCreator {
3535
}
3636

3737
dispose(): void {
38-
this._dispatcher = null;
38+
(this as any)._dispatcher = undefined;
3939
}
4040

4141
dispatcher(): ConnectionActionDispatcher {

src/client/script/output/NotificationPresenter.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ export class NotificationPresenter {
6868
this._disposeRequestPermission.unsubscribe();
6969
this._disposeshowNotification.unsubscribe();
7070

71-
this._audio = null;
72-
this._disposePlay = null;
73-
this._disposeRequestPermission = null;
74-
this._disposeshowNotification = null;
71+
this._audio.destroy();
7572
}
7673

7774
playSound(): void {

src/client/script/output/WindowPresenter.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ export class WindowPresenter implements EventListenerObject {
4141
private _domain: DomainState;
4242
private _disposer: Rx.Subscription;
4343

44-
private _currenTab: SelectedTab;
44+
private _currenTab: SelectedTab | void;
4545

4646
constructor(domain: DomainState) {
4747
this._domain = domain;
4848
this._disposer = new Rx.Subscription();
4949

5050
this._disposer.add(AppActionCreator.dispatcher().reload.subscribe(function () {
51-
window.onbeforeunload = null;
51+
(window as any).onbeforeunload = null;
5252

5353
location.reload();
5454
}));
@@ -63,7 +63,7 @@ export class WindowPresenter implements EventListenerObject {
6363
}
6464
}));
6565

66-
this._currenTab = null;
66+
this._currenTab = undefined;
6767
this._disposer.add(domain.getCurrentTab().subscribe((tab) => {
6868
this._currenTab = tab;
6969
}));
@@ -115,10 +115,6 @@ export class WindowPresenter implements EventListenerObject {
115115
window.document.documentElement.removeEventListener('keydown', this);
116116

117117
this._disposer.unsubscribe();
118-
119-
this._currenTab = null;
120-
this._disposer = null;
121-
this._domain = null;
122118
}
123119

124120
private _onBeforeUnload(aEvent: Event): string {
@@ -166,10 +162,16 @@ export class WindowPresenter implements EventListenerObject {
166162

167163
handleShortcut(key: string): void {
168164
const channelList: Array<Channel> = this._domain.networkSet.getChannelList();
169-
const currentIndex: Option<ChannelId> = this._domain.currentTab.channelId.map(function(currentId: ChannelId) {
170-
return channelList.findIndex(function(channel: Channel){
165+
const currentIndex: Option<ChannelId> = this._domain.currentTab.channelId.map(function(currentId: ChannelId): number {
166+
const result = channelList.findIndex(function(channel: Channel){
171167
return channel.id === currentId;
172168
});
169+
if (result === undefined) {
170+
throw new Error('should not be undefined');
171+
}
172+
else {
173+
return result;
174+
}
173175
});
174176

175177
if (currentIndex.isNone) {
@@ -213,4 +215,4 @@ export class WindowPresenter implements EventListenerObject {
213215
const title = BASE_TITLE + ' - ' + currentName;
214216
window.document.title = title;
215217
}
216-
}
218+
}

src/client/script/output/context/ConnectSettingContext.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class ConnectSettingContext implements ViewContext {
4040

4141
private _action: ConnectionActionCreator;
4242
private _store: ConnectionStore;
43-
private _viewDisposer: Rx.Subscription;
43+
private _viewDisposer: Rx.Subscription | undefined;
4444

4545
constructor(gateway: MessageGateway) {
4646
if (!gateway) {
@@ -49,17 +49,13 @@ export class ConnectSettingContext implements ViewContext {
4949

5050
this._action = new ConnectionActionCreator();
5151
this._store = new ConnectionStore(this._action.dispatcher(), gateway);
52-
this._viewDisposer = null;
52+
this._viewDisposer = undefined;
5353
}
5454

5555
private _destroy(): void {
56-
this._viewDisposer.unsubscribe();
56+
this._viewDisposer!.unsubscribe();
5757
this._store.dispose();
5858
this._action.dispose();
59-
60-
this._viewDisposer = null;
61-
this._store = null;
62-
this._action = null;
6359
}
6460

6561
onActivate(mountpoint: Element): void {

src/client/script/output/context/SidebarContext.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,16 @@ import {ViewContext} from './ViewContext';
3636
export class SidebarContext implements ViewContext {
3737

3838
private _viewmodel: SidebarStore;
39-
private _viewDisposer: Rx.Subscription;
39+
private _viewDisposer: Rx.Subscription | void;
4040

4141
constructor(domain: DomainState) {
4242
this._viewmodel = new SidebarStore(domain);
43-
this._viewDisposer = null;
43+
this._viewDisposer = undefined;
4444
}
4545

4646
private _destroy(): void {
4747
this._viewDisposer.unsubscribe();
4848
this._viewmodel.dispose();
49-
50-
this._viewDisposer = null;
51-
this._viewmodel = null;
5249
}
5350

5451
onActivate(mountpoint: Element): void {

src/client/script/output/view/AppView.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class AppViewModel {
4747

4848
export class AppView {
4949

50-
private _element: Element;
50+
private _element: Element | void;
5151
private _vm: AppViewModel;
5252
private _disposer: Rx.Subscription;
5353

@@ -67,7 +67,7 @@ export class AppView {
6767
}
6868

6969
destroy(): void {
70-
this._element = null;
70+
this._element = undefined;
7171
this._vm.destroy();
7272
this._disposer.unsubscribe();
7373
}
@@ -102,7 +102,7 @@ export class AppView {
102102
}
103103

104104
private _handleClickEvent(): Rx.Subscription {
105-
return Rx.Observable.fromEvent<Element>(this._element, 'click', (event: UIEvent) => event.target as Element)
105+
return Rx.Observable.fromEvent<Element>(this._element!, 'click', (event: UIEvent) => event.target as Element)
106106
.filter((target: Element): boolean => (target.localName === 'button'))
107107
.subscribe((target: Element) => {
108108
if (target.classList.contains('lt')) {

src/client/script/output/view/GeneralSettingView.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class GeneralSettingView implements EventListenerObject {
6969
const name = target.getAttribute('name');
7070
const value = (target as HTMLInputElement).checked;
7171

72-
SettingActionCreator.setOption(name, value);
72+
SettingActionCreator.setOption(name!, value);
7373

7474
if (value && target.getAttribute('id') === 'badge') {
7575
NotificationActionCreator.requestPermission();

src/client/script/output/view/InputBoxView.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class InputBoxView {
6161
private _disposer: Rx.Subscription;
6262

6363
private _inputVal: InputValue;
64-
private _lastSuggestionCache: Array<string>;
64+
private _lastSuggestionCache: Array<string> | undefined;
6565
private _isSuggestion: boolean;
6666

6767
constructor(domain: DomainState, element: Element) {
@@ -99,7 +99,7 @@ export class InputBoxView {
9999
}));
100100

101101
this._inputVal = new InputValue('', new None<number>());
102-
this._lastSuggestionCache = null;
102+
this._lastSuggestionCache = undefined;
103103
this._isSuggestion = false;
104104

105105
this._init();
@@ -201,16 +201,16 @@ export class InputBoxView {
201201
}
202202
else {
203203
const newly = this._inputVal.suggstedIndex.unwrap() + 1;
204-
index = (newly > (this._lastSuggestionCache.length - 1)) ? 0 : newly;
204+
index = (newly > (this._lastSuggestionCache!.length - 1)) ? 0 : newly;
205205
}
206206

207-
if (this._lastSuggestionCache.length === 0) {
207+
if (this._lastSuggestionCache!.length === 0) {
208208
return;
209209
}
210210

211211
this._inputVal = new InputValue(this._inputVal.actual, new Some(index));
212212
this._isSuggestion = true;
213-
this._textInput.value = this._lastSuggestionCache[index];
213+
this._textInput.value = this._lastSuggestionCache![index];
214214
this._isSuggestion = false;
215215
}
216216

@@ -230,7 +230,7 @@ export class InputBoxView {
230230

231231
const current = this._textInput.value;
232232
this._inputVal = new InputValue(current, new None<number>());
233-
this._lastSuggestionCache = null;
233+
this._lastSuggestionCache = undefined;
234234
}
235235

236236
private _createSuggestion(value: string): Array<string> {

0 commit comments

Comments
 (0)