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

Commit

Permalink
Auto merge of #604 - saneyuki:nullable, r=saneyuki
Browse files Browse the repository at this point in the history
chore(TypeScript): Enable 'strictNullChecks' option

This tries to enable [`--strictNullChecks` option](microsoft/TypeScript#7140) of TypeScript compiler.

- [Non-nullable types by ahejlsberg · Pull Request #7140 · Microsoft/TypeScript](microsoft/TypeScript#7140)
  - [Non-strict type checking · Issue #7489 · Microsoft/TypeScript](microsoft/TypeScript#7489)
  - [[Request for feedback] Nullable types, `null` and `undefined` · Issue #7426 · Microsoft/TypeScript](microsoft/TypeScript#7426)
- [Control flow based type analysis by ahejlsberg · Pull Request #8010 · Microsoft/TypeScript](microsoft/TypeScript#8010)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/karen-irc/karen/604)
<!-- Reviewable:end -->
  • Loading branch information
dokidokivisual committed May 4, 2016
2 parents 1bda2f9 + 9660b36 commit 25ed88b
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 99 deletions.
6 changes: 3 additions & 3 deletions src/client/rize/adapter/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ function requestPermittion(): Rx.Observable<boolean> {
}

function showNotification(topic: NotifedTopic): Rx.Observable<void> {
let notification: Notification = new (window as any).Notification(topic.title, {
let notification: Notification | void = new (window as any).Notification(topic.title, {
body: topic.body,
icon: topic.icon,
});
const timeout = Rx.Observable.empty<void>().delay(5 * 1000);
const click = Rx.Observable.fromEvent<void>(notification, 'click').take(1);
const click = Rx.Observable.fromEvent<void>(notification!, 'click').take(1);
const close: Rx.Observable<void> = click.race(timeout).do(function(){
notification.close();
notification = null;
notification = undefined;
});
return close.share();
}
2 changes: 1 addition & 1 deletion src/client/rize/rize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class RizeClient {
console.log(data.value);
});

const view = React.createElement(RizeAppView, null);
const view = React.createElement(RizeAppView, undefined);
const mountpoint = document.getElementById('js-mountpoint-app');
ReactDOM.render(view, mountpoint);
}
Expand Down
6 changes: 5 additions & 1 deletion src/client/script/adapter/AudioDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

export class AudioDriver {
_audio: HTMLAudioElement;
private _audio: HTMLAudioElement | void;

constructor(path: string) {
const audio = new Audio();
Expand All @@ -34,6 +34,10 @@ export class AudioDriver {
this._audio = audio;
}

destroy(): void {
this._audio = undefined;
}

play(): void {
this._audio.play();
}
Expand Down
11 changes: 4 additions & 7 deletions src/client/script/domain/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export class Channel {
private _userList: Array<User>;
private _unread: number;
private _messageBuffer: Array<Message>;
private _network: Network;
private _network: Network | void;

constructor(raw: any, network: Network = null) {
constructor(raw: any, network: Network | void = undefined) {
this.id = raw.id;

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

this._unread = raw.unread;

let messages: Array<Message> = null;
let messages: Array<Message> = [];
if (Array.isArray(raw.messages)) {
messages = raw.messages;
}
else {
messages = [];
}

this._messageBuffer = messages;
this._network = network;
Expand All @@ -79,7 +76,7 @@ export class Channel {
return this._userList;
}

getNetwork(): Network {
getNetwork(): Network | void {
return this._network;
}

Expand Down
1 change: 0 additions & 1 deletion src/client/script/domain/ChannelDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export class ChannelDomain {

dispose(): void {
this._ignitionDisposable.unsubscribe();
this._notableDispatcher = null;
}

getId(): ChannelId {
Expand Down
18 changes: 9 additions & 9 deletions src/client/script/domain/DomainState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ export class SelectedTab {
export class DomainState {

private _networkSet: NetworkSetDomain;
private _latestCurrentTab: SelectedTab;
private _latestCurrentTab: SelectedTab | void;
private _currentTab: Rx.Observable<SelectedTab>;
private _notifiableMessage: Rx.Observable<RecievedMessage>;

constructor(gateway: MessageGateway) {
this._networkSet = new NetworkSetDomain(gateway);
this._latestCurrentTab = null;
this._latestCurrentTab = undefined;

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

this._notifiableMessage = this._networkSet.recievedNotifiableMessage()
.withLatestFrom(this._currentTab, function (data, current): RecievedMessage {
.withLatestFrom(this._currentTab, function (data, current): RecievedMessage | void {
const isSameChannel: boolean = current.channelId.mapOr(false, function (current: ChannelId) {
return data.channelId === current;
});
if (isSameChannel) {
return null;
return undefined;
}

return data;
}).filter(function (data) {
return data !== null;
}).share();
return data !== undefined;
}).map((data) => data!).share();
}

/**
Expand All @@ -100,7 +100,7 @@ export class DomainState {
return this._networkSet.legacy;
}

get currentTab(): SelectedTab {
get currentTab(): SelectedTab | void {
return this._latestCurrentTab;
}

Expand Down Expand Up @@ -155,7 +155,7 @@ function selectTab(gateway: MessageGateway, intent: UIActionDispatcher, set: Net
});

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

const initial = set.initialState().map(function(data){
let tab: SelectedTab = null;
let tab: SelectedTab;

const idIsSetting = data.active.mapOr(true, function(id){
return (typeof id !== 'number');
Expand Down
8 changes: 0 additions & 8 deletions src/client/script/domain/NetworkDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,7 @@ export class NetworkDomain {
}

dispose(): void {
this._data = null;
this._nickname = null;
this._joinedChannel = null;
this._partedChannel = null;

this._notableMsgDispatcher = null;

this._subscribed.unsubscribe();
this._subscribed = null;
}

getId(): number {
Expand Down
2 changes: 1 addition & 1 deletion src/client/script/intent/action/ConnectionActionCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ConnectionActionCreator {
}

dispose(): void {
this._dispatcher = null;
(this as any)._dispatcher = undefined;
}

dispatcher(): ConnectionActionDispatcher {
Expand Down
5 changes: 1 addition & 4 deletions src/client/script/output/NotificationPresenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ export class NotificationPresenter {
this._disposeRequestPermission.unsubscribe();
this._disposeshowNotification.unsubscribe();

this._audio = null;
this._disposePlay = null;
this._disposeRequestPermission = null;
this._disposeshowNotification = null;
this._audio.destroy();
}

playSound(): void {
Expand Down
22 changes: 12 additions & 10 deletions src/client/script/output/WindowPresenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export class WindowPresenter implements EventListenerObject {
private _domain: DomainState;
private _disposer: Rx.Subscription;

private _currenTab: SelectedTab;
private _currenTab: SelectedTab | void;

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

this._disposer.add(AppActionCreator.dispatcher().reload.subscribe(function () {
window.onbeforeunload = null;
(window as any).onbeforeunload = null;

location.reload();
}));
Expand All @@ -63,7 +63,7 @@ export class WindowPresenter implements EventListenerObject {
}
}));

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

this._disposer.unsubscribe();

this._currenTab = null;
this._disposer = null;
this._domain = null;
}

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

handleShortcut(key: string): void {
const channelList: Array<Channel> = this._domain.networkSet.getChannelList();
const currentIndex: Option<ChannelId> = this._domain.currentTab.channelId.map(function(currentId: ChannelId) {
return channelList.findIndex(function(channel: Channel){
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) {
Expand Down Expand Up @@ -213,4 +215,4 @@ export class WindowPresenter implements EventListenerObject {
const title = BASE_TITLE + ' - ' + currentName;
window.document.title = title;
}
}
}
10 changes: 3 additions & 7 deletions src/client/script/output/context/ConnectSettingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ConnectSettingContext implements ViewContext {

private _action: ConnectionActionCreator;
private _store: ConnectionStore;
private _viewDisposer: Rx.Subscription;
private _viewDisposer: Rx.Subscription | undefined;

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

this._action = new ConnectionActionCreator();
this._store = new ConnectionStore(this._action.dispatcher(), gateway);
this._viewDisposer = null;
this._viewDisposer = undefined;
}

private _destroy(): void {
this._viewDisposer.unsubscribe();
this._viewDisposer!.unsubscribe();
this._store.dispose();
this._action.dispose();

this._viewDisposer = null;
this._store = null;
this._action = null;
}

onActivate(mountpoint: Element): void {
Expand Down
7 changes: 2 additions & 5 deletions src/client/script/output/context/SidebarContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,16 @@ import {ViewContext} from './ViewContext';
export class SidebarContext implements ViewContext {

private _viewmodel: SidebarStore;
private _viewDisposer: Rx.Subscription;
private _viewDisposer: Rx.Subscription | void;

constructor(domain: DomainState) {
this._viewmodel = new SidebarStore(domain);
this._viewDisposer = null;
this._viewDisposer = undefined;
}

private _destroy(): void {
this._viewDisposer.unsubscribe();
this._viewmodel.dispose();

this._viewDisposer = null;
this._viewmodel = null;
}

onActivate(mountpoint: Element): void {
Expand Down
6 changes: 3 additions & 3 deletions src/client/script/output/view/AppView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AppViewModel {

export class AppView {

private _element: Element;
private _element: Element | void;
private _vm: AppViewModel;
private _disposer: Rx.Subscription;

Expand All @@ -67,7 +67,7 @@ export class AppView {
}

destroy(): void {
this._element = null;
this._element = undefined;
this._vm.destroy();
this._disposer.unsubscribe();
}
Expand Down Expand Up @@ -102,7 +102,7 @@ export class AppView {
}

private _handleClickEvent(): Rx.Subscription {
return Rx.Observable.fromEvent<Element>(this._element, 'click', (event: UIEvent) => event.target as Element)
return Rx.Observable.fromEvent<Element>(this._element!, 'click', (event: UIEvent) => event.target as Element)
.filter((target: Element): boolean => (target.localName === 'button'))
.subscribe((target: Element) => {
if (target.classList.contains('lt')) {
Expand Down
2 changes: 1 addition & 1 deletion src/client/script/output/view/GeneralSettingView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class GeneralSettingView implements EventListenerObject {
const name = target.getAttribute('name');
const value = (target as HTMLInputElement).checked;

SettingActionCreator.setOption(name, value);
SettingActionCreator.setOption(name!, value);

if (value && target.getAttribute('id') === 'badge') {
NotificationActionCreator.requestPermission();
Expand Down
12 changes: 6 additions & 6 deletions src/client/script/output/view/InputBoxView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class InputBoxView {
private _disposer: Rx.Subscription;

private _inputVal: InputValue;
private _lastSuggestionCache: Array<string>;
private _lastSuggestionCache: Array<string> | undefined;
private _isSuggestion: boolean;

constructor(domain: DomainState, element: Element) {
Expand Down Expand Up @@ -99,7 +99,7 @@ export class InputBoxView {
}));

this._inputVal = new InputValue('', new None<number>());
this._lastSuggestionCache = null;
this._lastSuggestionCache = undefined;
this._isSuggestion = false;

this._init();
Expand Down Expand Up @@ -201,16 +201,16 @@ export class InputBoxView {
}
else {
const newly = this._inputVal.suggstedIndex.unwrap() + 1;
index = (newly > (this._lastSuggestionCache.length - 1)) ? 0 : newly;
index = (newly > (this._lastSuggestionCache!.length - 1)) ? 0 : newly;
}

if (this._lastSuggestionCache.length === 0) {
if (this._lastSuggestionCache!.length === 0) {
return;
}

this._inputVal = new InputValue(this._inputVal.actual, new Some(index));
this._isSuggestion = true;
this._textInput.value = this._lastSuggestionCache[index];
this._textInput.value = this._lastSuggestionCache![index];
this._isSuggestion = false;
}

Expand All @@ -230,7 +230,7 @@ export class InputBoxView {

const current = this._textInput.value;
this._inputVal = new InputValue(current, new None<number>());
this._lastSuggestionCache = null;
this._lastSuggestionCache = undefined;
}

private _createSuggestion(value: string): Array<string> {
Expand Down
Loading

0 comments on commit 25ed88b

Please sign in to comment.