Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

HappyRish01
Copy link

feat: Migrated [chartData.js, events.js, searchParams] to TypeScript

This PR addresses issue #167 (migrating the codebase into typescript)

Copy link

netlify bot commented Mar 9, 2025

Deploy Preview for gsoc-organizations ready!

Name Link
🔨 Latest commit 8d76fa3
🔍 Latest deploy log https://app.netlify.com/sites/gsoc-organizations/deploys/67cd2eac709b19000896be4a
😎 Deploy Preview https://deploy-preview-171--gsoc-organizations.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Owner

@nishantwrp nishantwrp left a 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.
Copy link
Owner

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.

Copy link
Owner

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
Copy link
Owner

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 {
Copy link
Owner

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 {
Copy link
Owner

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
Copy link
Owner

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 {
Copy link
Owner

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)
  }
}

Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants