-
Notifications
You must be signed in to change notification settings - Fork 680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore constructor props commits #4716
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,19 +41,18 @@ export type ChanConfig = { | |
}; | ||
|
||
class Chan { | ||
// TODO: don't force existence, figure out how to make TS infer it. | ||
id!: number; | ||
messages!: Msg[]; | ||
name!: string; | ||
key!: string; | ||
topic!: string; | ||
firstUnread!: number; | ||
unread!: number; | ||
highlight!: number; | ||
users!: Map<string, User>; | ||
muted!: boolean; | ||
type!: ChanType; | ||
state!: ChanState; | ||
id: number; | ||
messages: Msg[]; | ||
name: string; | ||
key: string; | ||
topic: string; | ||
firstUnread: number; | ||
unread: number; | ||
highlight: number; | ||
users: Map<string, User>; | ||
muted: boolean; | ||
type: ChanType; | ||
state: ChanState; | ||
|
||
userAway?: boolean; | ||
special?: SpecialChanType; | ||
|
@@ -63,20 +62,22 @@ class Chan { | |
static optionalProperties = ["userAway", "special", "data", "closed", "num_users"]; | ||
|
||
constructor(attr?: Partial<Chan>) { | ||
_.defaults(this, attr, { | ||
id: 0, | ||
messages: [], | ||
name: "", | ||
key: "", | ||
topic: "", | ||
type: ChanType.CHANNEL, | ||
state: ChanState.PARTED, | ||
firstUnread: 0, | ||
unread: 0, | ||
highlight: 0, | ||
users: new Map(), | ||
muted: false, | ||
}); | ||
this.id = 0; | ||
this.messages = []; | ||
this.name = ""; | ||
this.key = ""; | ||
this.topic = ""; | ||
this.type = ChanType.CHANNEL; | ||
this.state = ChanState.PARTED; | ||
this.firstUnread = 0; | ||
this.unread = 0; | ||
this.highlight = 0; | ||
this.users = new Map(); | ||
this.muted = false; | ||
|
||
if (attr) { | ||
Object.assign(this, attr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a better fix would be make all of the parameters that chan creation uses explicit parameters of the constructor, such as Alternatively, it could be static helpers such as these comment also applies to the other models |
||
} | ||
} | ||
|
||
destroy() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a class now, why don't we assign all of these as defaults on the class properties instead of setting them in the constructors?