#How to read this in english?
36 messages · Page 1 of 1 (latest)
If property is not valid, strips values 4,5,7,8 from menuFilter
If that's not valid, 4,5,7,8 are excuded from menuFilter.
Moving this part to a function with proper naming can help you to maintain it.
Creating a unit test is the best solution to test your logic: you know the input and the output.
What is the psuedo algorithm? Like includes is iterating the array [4,5,7,8]?
I have to break this down, I know includes true or false through array.
If property is not valid keep only the elements not included in 4, 5, 7, 8
If this is real code, you should really define constants instead of using magic numbers, and add comments explaining why you exclude those values
What makes this hard is the senior dev used a md array.
//Status Manual Automated
let items = [
[[1,2], [1,2], [1,2]], //Waiting on Data
[[3], [1,2,3], []], //Ready for Agent
[[4], [1,4,6], []], //Waiting on Agent
[[5], [1,2,4,6], [1,2,4,6]], //Ready to Search
[[11], [4], [4]], //Waiting on Copies
[[6], [5], [5]], //Ready for Review
[[8], [7], [7]], //Ready for Release
[[10], [8], [8]], //Completed
[[99], [], []] //Canceled
];
To filter toolbar button validations.
It's the senior devs when we did pair programming and I am still having trouble with some of the md stuff.
Your senior developer looks quite junior to me
//Find the proper status id
let taskMenu = (items.find(f => f[0].includes(this.task.value.status.id))??[]);
let menuFilter: number[];
if (taskMenu.length === 0) {
// Default to first element if status is not found
this._logger.error("No matching status array element found, so default to Waiting on Data");
menuFilter = items[0][this.task.value.taskType] as number[];
}
else {
menuFilter = taskMenu[this.task.value.taskType] as number[];
}
He admits he is still learning Angular and we are learning together.
He knows how to get things working but admits we might be doing somethings wrong.
multi-dimensional arrays and number identifiers...
Is it a linear algebra course?
That's fine, but avoiding magic numbers is a general rule of development, unrelated to Angular
Oh the statuses in the md?
Lol dude it feels like that.
This was for tracking a filing and validating it through the steps.
Everything really. The statuses, the positions of the inner arrays, the fact that 0 means waiting on data. This is unmaintainable
Would you instead great objects for statuses?
I don't know your usecase well enough to suggest a solution, but I wouldn't use that, that's for sure.
I've been reading the docs like crazy. What else is the best resource for getting best practices down? What learning step should I take next?
This is test data
So the buttons up top, disable or enable based on status and validation
You upload a file to validate, and the system checks if it needs anything else based on file uploading/deleting.
This all works, but it was such a pain to get the buttons, dropdowns and components to update the data when switching to a different record.
But the MD is tied to those statuses.
Based on if it's automated or manually processed.
Read it but trying to make sense out of the take away point.
Like are we talking about our statuses being magic numbers and needing enums instead?
Oh I see after some more Googling. We shouldnt use the numbers directly. Need to be a variable?
I suggest that you review the various eslint rules and pick ones that appeal to you and your codebase. Automated code review and analysis can be helpful with keeping a minimum standard to your code.
Personally, I turn on all the rules and then just configure and disable the ones that I need to. But that does make linting slow and very strict.