-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
interface OrgYearData { | ||
[year: string]: { | ||
num_projects: number | ||
} | ||
} | ||
interface OrgChartData { | ||
years: number[] | ||
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 commentThe 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 commentThe 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. |
||
* @param allYears - An array of all years to consider. | ||
* @param orgYearData - An object containing organization data for specific years. | ||
* @returns An object containing the years to plot and the number of projects for each year. | ||
*/ | ||
|
||
export const createOrgChartData = ( | ||
allYears: number[], | ||
orgYearData: OrgYearData | ||
): OrgChartData => { | ||
// Filter and sort years, excluding 2025 | ||
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. nit: ditto, this comment doesn't seem to add any value. same below. |
||
const years = allYears | ||
.sort() | ||
.filter(item => item != 2025) | ||
.reduce((yearsToPlot: number[], year: number) => { | ||
if (yearsToPlot.length != 0) { | ||
yearsToPlot.push(year) | ||
return yearsToPlot | ||
} else { | ||
return Object.keys(orgYearData).includes(year.toString()) ? [year] : [] | ||
} | ||
}, []) | ||
// Calculate the number of projects for each year | ||
const numProjects = [] | ||
for (const year of years) { | ||
if (Object.keys(orgYearData).includes(year.toString())) { | ||
numProjects.push(orgYearData[year].num_projects) | ||
} else { | ||
numProjects.push(0) | ||
} | ||
} | ||
return { | ||
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. nit: newline above. |
||
years, | ||
numProjects, | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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 commentThe 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. |
||
private static _subscriberMap: Record<string, EventCallBack[]> = {} | ||
|
||
/** | ||
* Emit an event with a payload to all subscribers. | ||
* @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 commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, can you think of ideas to avoid 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 commentThe reason will be displayed to describe this comment to others. Learn more. Let me know if you have better ideas. |
||
if (!this._subscriberMap[eventName]) return | ||
this._subscriberMap[eventName].forEach(callback => callback(payload)) | ||
} | ||
/** | ||
* Subscribe to an event. | ||
* @param eventName - The name of the event to subscribe to. | ||
* @param callback - The function to call when the event is emitted. | ||
*/ | ||
static subscribe<T = any>( | ||
eventName: string, | ||
callback: EventCallBack<T> | ||
): void { | ||
if (!this._subscriberMap[eventName]) this._subscriberMap[eventName] = [] | ||
this._subscriberMap[eventName].push(callback) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"checkJs": true, | ||
"outDir": "./dist", | ||
"rootDir": "./", | ||
"module": "commonjs", | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"target": "es5", | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true | ||
} | ||
} |
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