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

Commit

Permalink
#57: use "readonly state" initialization instead of ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
PzYon committed Aug 22, 2018
1 parent 8ee1ce6 commit ff7a3c1
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 78 deletions.
12 changes: 4 additions & 8 deletions client/src/AuthenticatedApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,10 @@ interface IAppState {
}

export class AuthenticatedApp extends React.Component<{}, IAppState> {
public constructor(props: {}) {
super(props);

this.state = {
currentUser: null,
isLoading: true
};
}
public readonly state: IAppState = {
currentUser: null,
isLoading: true
};

public componentDidMount(): void {
AuthenticatedServerApi.get("users/me")
Expand Down
7 changes: 3 additions & 4 deletions client/src/common/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ interface IErrorBoundaryState {
}

export class ErrorBoundary extends React.PureComponent<{}, IErrorBoundaryState> {
public constructor(props: {}) {
super(props);
this.state = { error: undefined };
}
public readonly state: IErrorBoundaryState = {
error: undefined
};

public static ensureError(component: React.Component, error: Error) {
component.setState(() => {
Expand Down
10 changes: 4 additions & 6 deletions client/src/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ interface IHeaderState {
}

export class Header extends React.PureComponent<IHeaderProps, IHeaderState> {
public constructor(props: IHeaderProps) {
super(props);

this.state = {
title: ""
};
public readonly state: IHeaderState = {
title: ""
};

public componentDidMount(): void {
new Typer("engraved.").startTyping((typedText: string) => this.setState({ title: typedText }));
}

Expand Down
10 changes: 3 additions & 7 deletions client/src/common/form/fields/markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,9 @@ interface IMarkdownState {
const tocSeparator = "---ngrvd-separator---";

export class Markdown extends React.PureComponent<IMarkdownProps, IMarkdownState> {
public constructor(props: IMarkdownProps) {
super(props);

this.state = {
isTocExpanded: false
};
}
public readonly state: IMarkdownState = {
isTocExpanded: false
};

public render(): ReactNode {
if (!this.props.markdown || !this.props.markdown.trim()) {
Expand Down
10 changes: 3 additions & 7 deletions client/src/common/form/fields/markdown/MarkdownField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ interface IMarkdownFieldState {
}

export class MarkdownField extends React.PureComponent<IMarkdownFieldProps, IMarkdownFieldState> {
public constructor(props: IMarkdownFieldProps) {
super(props);

this.state = {
isPreview: false
};
}
public readonly state: IMarkdownFieldState = {
isPreview: false
};

public render(): ReactNode {
return (
Expand Down
14 changes: 5 additions & 9 deletions client/src/common/searchBox/SearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,11 @@ interface ISearchBoxState {
export class SearchBox extends React.Component<ISearchBoxProps, ISearchBoxState> {
private node: HTMLDivElement;

public constructor(props: ISearchBoxProps) {
super(props);

this.state = {
showDropDown: true,
hidePlaceholder: false,
hasFocus: false
};
}
public readonly state: ISearchBoxState = {
showDropDown: true,
hidePlaceholder: false,
hasFocus: false
};

public render(): ReactNode {
return (
Expand Down
10 changes: 3 additions & 7 deletions client/src/items/url/ViewUrlItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ export class ViewUrlItem extends React.PureComponent<IViewItemProps<IUrlItem>, I

private imageAnchorEl: HTMLImageElement;

public constructor(props: IViewItemProps<IUrlItem>) {
super(props);

this.state = {
showFallbackIcon: false
};
}
public readonly state: IViewUrlItemState = {
showFallbackIcon: false
};

public render(): ReactNode {
return (
Expand Down
10 changes: 3 additions & 7 deletions client/src/notifications/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,9 @@ interface INotificationsState {
export class Notifications extends React.PureComponent<{}, INotificationsState> {
private notifications$Subscription: Subscription;

public constructor(props: {}) {
super(props);

this.state = {
notifications: []
};
}
public readonly state: INotificationsState = {
notifications: []
};

public componentDidMount(): void {
this.notifications$Subscription = NotificationStore.instance.notifications$.subscribe(
Expand Down
32 changes: 14 additions & 18 deletions client/src/pages/search/GlobalSearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,27 @@ interface IGlobalSearchBoxState {
export class GlobalSearchBox extends React.PureComponent<{}, IGlobalSearchBoxState> {
private findOnTypeTimer: any;

private keywordsSubscription: Subscription;

public constructor(props: {}) {
super(props);

this.state = {
searchValue: ItemStore.instance.searchText,
keywordSearchValue: "",
showDropDown: true,
actionDropDownItems: [],
keywordDropDownItems: [],
selectedKeywords: [],
redirectToUrl: null
};
}
private keywords$Subscription: Subscription;

public readonly state: IGlobalSearchBoxState = {
searchValue: ItemStore.instance.searchText,
keywordSearchValue: "",
showDropDown: true,
actionDropDownItems: [],
keywordDropDownItems: [],
selectedKeywords: [],
redirectToUrl: null
};

public componentDidMount(): void {
this.keywordsSubscription = ItemStore.instance.keywords$.subscribe(keywords =>
this.keywords$Subscription = ItemStore.instance.keywords$.subscribe(keywords =>
this.setState({ selectedKeywords: keywords })
);
}

public componentWillUnmount(): void {
if (this.keywordsSubscription) {
this.keywordsSubscription.unsubscribe();
if (this.keywords$Subscription) {
this.keywords$Subscription.unsubscribe();
}
}

Expand Down
8 changes: 3 additions & 5 deletions client/src/pages/search/results/ItemsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ interface IListOfItemsState {
export class ItemsList extends React.PureComponent<{}, IListOfItemsState> {
private items$Subscription: Subscription;

public constructor(props: {}) {
super(props);

this.state = { items: [] };
}
public readonly state: IListOfItemsState = {
items: []
};

public componentDidMount(): void {
this.items$Subscription = ItemStore.instance.items$.subscribe(
Expand Down

0 comments on commit ff7a3c1

Please sign in to comment.