Skip to content

Commit

Permalink
refactor: Update ActivityRoom constructor to use OnRunActivityEvent i…
Browse files Browse the repository at this point in the history
…nstead of a function type for the onRun parameter
  • Loading branch information
BlackRam-oss committed May 16, 2024
1 parent 60fa347 commit 7fd1e70
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions src/classes/Activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,17 @@ export interface ActivityProps {
icon?: GraphicItemType
}

/**
* The function that is called when the activity is runned.
*/
export type OnRunActivityEvent<T> = (activity: T, yourParams?: { [key: string]: any }) => void

export abstract class ActivityStoredAbstract {
constructor(onRun: (activity: ActivityStoredAbstract) => void, props: ActivityProps) {
/**
* @param onRun The function that is called when the activity is runned. Have 2 parameters: the runned activity and the yourParams object, that is an object with the parameters that you want to pass to the onRun function.
* @param props The activity properties.
*/
constructor(onRun: OnRunActivityEvent<ActivityStoredAbstract>, props: ActivityProps) {
this.defaultName = props.name
this.defaultFromHour = props.fromHour
this.defaultToHour = props.toHour
Expand Down Expand Up @@ -170,8 +179,16 @@ export abstract class ActivityStoredAbstract {
}
}

/**
* The activity model.
*/
export default class ActivityModel {
constructor(id: string, onRun: (activity: ActivityModel) => void, props: ActivityProps) {
/**
* @param id The activity id, that must be unique.
* @param onRun The function that is called when the activity is runned. Have 2 parameters: the runned activity and the yourParams object, that is an object with the parameters that you want to pass to the onRun function.
* @param props The activity properties.
*/
constructor(id: string, onRun: OnRunActivityEvent<ActivityModel>, props: ActivityProps) {
this._id = id
this._name = props.name
this._fromHour = props.fromHour
Expand Down Expand Up @@ -241,7 +258,7 @@ export default class ActivityModel {
return this._icon
}

private _onRun: (activity: ActivityModel) => void
private _onRun: OnRunActivityEvent<ActivityModel>
get onRun(): () => void {
return () => this._onRun(this)
}
Expand Down
4 changes: 2 additions & 2 deletions src/classes/navigation/ActivityRoom.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ActivityProps, ActivityStoredAbstract } from "../Activity";
import { ActivityProps, ActivityStoredAbstract, OnRunActivityEvent } from "../Activity";
import RoomBaseModel from "./Room";

export class ActivityRoom<TRoom extends RoomBaseModel = RoomBaseModel> extends ActivityStoredAbstract {
constructor(id: string, room: TRoom, onRun: (activity: ActivityStoredAbstract) => void, props: ActivityProps) {
constructor(id: string, room: TRoom, onRun: OnRunActivityEvent<ActivityStoredAbstract>, props: ActivityProps) {
super(onRun, props)
this._id = id
this._room = room
Expand Down

0 comments on commit 7fd1e70

Please sign in to comment.