Skip to content

Commit 0cf3d61

Browse files
committed
course: convert all actions to arrow functions
1 parent fd7b379 commit 0cf3d61

File tree

6 files changed

+215
-209
lines changed

6 files changed

+215
-209
lines changed

src/packages/frontend/course/actions.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,34 @@ export class CourseActions extends Actions<CourseState> {
6464
this.export = bind_methods(new ExportActions(this));
6565
}
6666

67-
public get_store(): CourseStore {
67+
get_store = (): CourseStore => {
6868
const store = this.redux.getStore<CourseState, CourseStore>(this.name);
6969
if (store == null) throw Error("store is null");
7070
if (!this.store_is_initialized())
7171
throw Error("course store must be initialized");
7272
this.state = "ready"; // this is pretty dumb for now.
7373
return store;
74-
}
74+
};
7575

76-
public is_closed(): boolean {
76+
is_closed = (): boolean => {
7777
if (this.state == "closed") return true;
7878
const store = this.redux.getStore<CourseState, CourseStore>(this.name);
7979
if (store == null) {
8080
this.state = "closed";
8181
return true;
8282
}
8383
return false;
84-
}
84+
};
8585

86-
private is_loaded(): boolean {
86+
private is_loaded = (): boolean => {
8787
if (this.syncdb == null) {
8888
this.set_error("attempt to set syncdb before loading");
8989
return false;
9090
}
9191
return true;
92-
}
92+
};
9393

94-
private store_is_initialized(): boolean {
94+
private store_is_initialized = (): boolean => {
9595
const store = this.redux.getStore<CourseState, CourseStore>(this.name);
9696
if (store == null) {
9797
return false;
@@ -107,7 +107,7 @@ export class CourseActions extends Actions<CourseState> {
107107
return false;
108108
}
109109
return true;
110-
}
110+
};
111111

112112
// Set one object in the syncdb
113113
set = (obj: SyncDBRecord, commit: boolean = true): void => {
@@ -145,7 +145,7 @@ export class CourseActions extends Actions<CourseState> {
145145
};
146146

147147
// Get one object from this.syncdb as a Javascript object (or undefined)
148-
public get_one(obj: SyncDBRecord): SyncDBRecord | undefined {
148+
get_one = (obj: SyncDBRecord): SyncDBRecord | undefined => {
149149
if (
150150
this.syncdb != null ? this.syncdb.get_state() === "closed" : undefined
151151
) {
@@ -154,9 +154,9 @@ export class CourseActions extends Actions<CourseState> {
154154
const x: any = this.syncdb.get_one(obj);
155155
if (x == null) return;
156156
return x.toJS();
157-
}
157+
};
158158

159-
public async save(): Promise<void> {
159+
save = async (): Promise<void> => {
160160
const store = this.get_store();
161161
if (store == null) {
162162
return;
@@ -179,9 +179,9 @@ export class CourseActions extends Actions<CourseState> {
179179
this.update_unsaved_changes();
180180
setTimeout(this.update_unsaved_changes.bind(this), 1000);
181181
}
182-
}
182+
};
183183

184-
public syncdb_change(changes: TypedMap<SyncDBRecord>[]): void {
184+
syncdb_change = (changes: TypedMap<SyncDBRecord>[]): void => {
185185
let t;
186186
const store = this.get_store();
187187
if (store == null) {
@@ -219,18 +219,18 @@ export class CourseActions extends Actions<CourseState> {
219219
this.setState(t);
220220
}
221221
this.update_unsaved_changes();
222-
}
222+
};
223223

224-
private update_unsaved_changes(): void {
224+
private update_unsaved_changes = (): void => {
225225
if (this.syncdb == null) {
226226
return;
227227
}
228228
const unsaved = this.syncdb.has_unsaved_changes();
229229
this.setState({ unsaved });
230-
}
230+
};
231231

232232
// important that this be bound...
233-
public handle_projects_store_update(projects_store: ProjectsStore): void {
233+
handle_projects_store_update = (projects_store: ProjectsStore): void => {
234234
const store = this.redux.getStore<CourseState, CourseStore>(this.name);
235235
if (store == null) return; // not needed yet.
236236
let users = projects_store.getIn([
@@ -248,12 +248,12 @@ export class CourseActions extends Actions<CourseState> {
248248
this.student_projects.configure_all_projects();
249249
}
250250
this.last_collaborator_state = users;
251-
}
251+
};
252252

253253
// Set the error. Use error="" to explicitly clear the existing set error.
254254
// If there is an error already set, then the new error is just
255255
// appended to the existing one.
256-
public set_error(error: string): void {
256+
set_error = (error: string): void => {
257257
if (error != "") {
258258
const store = this.get_store();
259259
if (store == null) return;
@@ -263,18 +263,18 @@ export class CourseActions extends Actions<CourseState> {
263263
error = error.trim();
264264
}
265265
this.setState({ error });
266-
}
266+
};
267267

268268
// ACTIVITY ACTIONS
269-
public set_activity = (
269+
set_activity = (
270270
opts: { id: number; desc?: string } | { id?: number; desc: string },
271271
): number => {
272272
return this.activity.set_activity(opts);
273273
};
274274

275-
public clear_activity(id?: number): void {
275+
clear_activity = (id?: number): void => {
276276
this.activity.clear_activity(id);
277-
}
277+
};
278278

279279
// CONFIGURATION ACTIONS
280280
// These hang off of this.configuration
@@ -302,12 +302,12 @@ export class CourseActions extends Actions<CourseState> {
302302
If something goes wrong and the finish function is defined, then
303303
it is called with a string describing the error.
304304
*/
305-
public resolve(opts: {
305+
resolve = (opts: {
306306
assignment_id?: string;
307307
student_id?: string;
308308
handout_id?: string;
309309
finish?: Function;
310-
}) {
310+
}) => {
311311
const r: {
312312
student?: StudentRecord;
313313
assignment?: AssignmentRecord;
@@ -359,20 +359,20 @@ export class CourseActions extends Actions<CourseState> {
359359
}
360360
}
361361
return r;
362-
}
362+
};
363363

364364
// Takes an item_name and the id of the time
365365
// item_name should be one of
366366
// ['student', 'assignment', 'peer_config', handout', 'skip_grading']
367-
public toggle_item_expansion(
367+
toggle_item_expansion = (
368368
item_name:
369369
| "student"
370370
| "assignment"
371371
| "peer_config"
372372
| "handout"
373373
| "skip_grading",
374374
item_id,
375-
): void {
375+
): void => {
376376
let adjusted;
377377
const store = this.get_store();
378378
if (store == null) {
@@ -391,5 +391,5 @@ export class CourseActions extends Actions<CourseState> {
391391
}
392392
}
393393
this.setState({ [field_name]: adjusted });
394-
}
394+
};
395395
}

src/packages/frontend/course/activity/actions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export class ActivityActions {
2020
this.actions = actions;
2121
}
2222

23-
public set_activity(
23+
set_activity = (
2424
opts: { id: number; desc?: string } | { id?: number; desc: string },
25-
): number {
25+
): number => {
2626
if (this.actions.is_closed()) return -1;
2727
if (opts.id == null) {
2828
this.activity_id += 1;
@@ -41,14 +41,14 @@ export class ActivityActions {
4141
}
4242
this.actions.setState({ activity });
4343
return opts.id;
44-
}
44+
};
4545

46-
public clear_activity(id?: number): void {
46+
clear_activity = (id?: number): void => {
4747
if (this.actions.is_closed()) return;
4848
if (id != null) {
4949
this.set_activity({ id }); // clears for this id since desc not provided
5050
} else {
5151
this.actions.setState({ activity: Map() }); // clear all activity
5252
}
53-
}
53+
};
5454
}

0 commit comments

Comments
 (0)