Skip to content
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

Remove unneeded ilios common slices #8116

Merged

Conversation

michaelchadwick
Copy link
Contributor

@michaelchadwick michaelchadwick commented Sep 4, 2024

References ilios/ilios#5660

Went through the packages/ilios-common directory and removed a bunch of slice()s. Left some I found because they had a .sort() or [1] or similar access thing that I know has thrown off our tests in the past.

Copy link
Member

@jrjohnson jrjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional refactoring possible and I think worth it for clarity. Also an open discussion item around passing a promise to RSVP.map without the interim variable.

return findById(objectives, objective.id);
});
this.isManagingParents = true;
});

manageDescriptors = dropTask(async () => {
const meshDescriptors = await this.args.courseObjective.meshDescriptors;
this.descriptorsBuffer = meshDescriptors.slice();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire purpose of this interim variable seems to be the slice. This might be the only time we notice this for a while so please replace with a direct assignment eg this.descriptorsBuffer = await this.args.courseObjective.meshDescriptors;

@@ -138,7 +138,7 @@ export default class LearningMaterialManagerComponent extends Component {
this.endDate = learningMaterial.endDate;

const meshDescriptors = await learningMaterial.get('meshDescriptors');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary interim var.

@@ -59,20 +59,20 @@ export default class SessionObjectiveListItemComponent extends Component {

manageParents = dropTask(async () => {
const parents = await this.args.sessionObjective.courseObjectives;
this.parentsBuffer = parents.slice();
this.parentsBuffer = parents;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary interim var.

this.isManagingParents = true;
});

manageDescriptors = dropTask(async () => {
const meshDescriptors = await this.args.sessionObjective.meshDescriptors;
this.descriptorsBuffer = meshDescriptors.slice();
this.descriptorsBuffer = meshDescriptors;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary interim var.

this.isManagingDescriptors = true;
});

manageTerms = dropTask(async (vocabulary) => {
this.selectedVocabulary = vocabulary;
const terms = await this.args.sessionObjective.terms;
this.termsBuffer = terms.slice();
this.termsBuffer = terms;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary interim var.

@@ -87,7 +87,7 @@ export default class SessionsGrid extends Component {
const offerings = await session.offerings;
const learnerGroups = await map(offerings, async (offering) => {
const learnerGroups = await offering.learnerGroups;
return learnerGroups.slice();
return learnerGroups;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary interim var.

@@ -15,7 +15,7 @@ export default class CourseVisualizeInstructorRoute extends Route {
}

async afterModel({ course }) {
const sessions = (await course.sessions).slice();
const sessions = await course.sessions;
return await all([course.school, map(sessions, (s) => s.sessionType)]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting thing here. It looks like RSVP.map will resolve a promise that is passed as the first argument. Really for discussion, but would it be cleaner to do this without the interim variable as just map(course.sessions, fn)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a cromulent change. Probably need to do this across the site, but I'm checking to see if the change kills any tests now.

@jrjohnson jrjohnson removed the request for review from stopfstedt September 9, 2024 16:15
Copy link
Member

@jrjohnson jrjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small additional since you're on this line already refactor and a left in log and comment from debugging.

const meshDescriptors = await learningMaterial.get('meshDescriptors');
this.terms = meshDescriptors.slice();

this.terms = await learningMaterial.get('meshDescriptors');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have noticed this the first time, sorry, this should be

Suggested change
this.terms = await learningMaterial.get('meshDescriptors');
this.terms = await learningMaterial.meshDescriptors;

and remove the old school Ember pattern of using get here.

const sessions = (await course.sessions).slice();
return await all([course.school, map(sessions, (s) => s.sessionType)]);
// const sessions = await course.sessions;
console.log('CourseVisualizeInstructorRoute');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OUTPUT: 😏

@michaelchadwick michaelchadwick merged commit bc440a1 into ilios:master Sep 10, 2024
41 of 42 checks passed
@michaelchadwick michaelchadwick deleted the remove-unneeded-ilios-common-slices branch September 13, 2024 23:07
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