-
-
Notifications
You must be signed in to change notification settings - Fork 72
Utils migration #171
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
base: master
Are you sure you want to change the base?
Utils migration #171
Conversation
✅ Deploy Preview for gsoc-organizations ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
Thanks @HappyRish01, left a few comments, ptal!
Also, it would be great if you can do git mv
when renaming files from .js
to .ts
. It would help to see the difference between two files easily.
numProjects: number[] | ||
} | ||
/** | ||
* Creates organization chart data based on the provided years and organization data. |
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.
I think we can skip this jsdoc. This doesn't say anything extra that isn't already clear by the types and naming of the function arguments.
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.
Just to clarify, there is no downsides of having these comments but just want to say that it's not worth spending time writing these unless they add some value.
allYears: number[], | ||
orgYearData: OrgYearData | ||
): OrgChartData => { | ||
// Filter and sort years, excluding 2025 |
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.
nit: ditto, this comment doesn't seem to add any value.
same below.
numProjects.push(0) | ||
} | ||
} | ||
return { |
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.
nit: newline above.
num_projects: number | ||
} | ||
} | ||
interface OrgChartData { |
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.
nit: newline above
type EventCallBack<T = any> = (payload: T) => void | ||
|
||
export class EventBus { | ||
// Define a static map to store event subscribers |
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.
ditto: these comments don't seem to add any value. I'd prefer skipping these.
* @param eventName - The name of the event to emit. | ||
* @param payload - The data to pass to the subscribers. | ||
*/ | ||
static emit<T = any>(eventName: string, payload: T): void { |
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.
Hmm, can you think of ideas to avoid any
here? We'd want the caller of this function to know what type should the payload be based on the eventName.
I was thinking something we can maintain a registry of all event types in this file.
type EventTypes = {
updateSearch: string;
}
type EventCallback<T> = (payload: T) => void
export class EventBus {
type SubscriberMap = {
[EventName in keyof EventTypes]: EventCallback<EventTypes[EventName]>[];
}
private static _subscriberMap: SubscriberMap = {}
static emit<T extends keyof EventTypes>(eventName: T, payload: EventTypes[T]): void {
if (!this._subscriberMap[eventName]) return
this._subscriberMap[eventName].forEach(callback => callback(payload))
}
static subscribe<T extends keyof EventTypes>(eventName: T, callback: EventCallback<EventTypes[T]>): void {
if (!this._subscriberMap[eventName]) this._subscriberMap[eventName] = []
this._subscriberMap[eventName].push(callback)
}
}
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.
Let me know if you have better ideas.
feat: Migrated [chartData.js, events.js, searchParams] to TypeScript
This PR addresses issue #167 (migrating the codebase into typescript)