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

Refactor user skills service #1011

Merged
merged 3 commits into from Feb 4, 2017
Merged

Refactor user skills service #1011

merged 3 commits into from Feb 4, 2017

Conversation

joshsmith
Copy link
Contributor

@joshsmith joshsmith commented Feb 3, 2017

Attempt to refactor user skills service to make it generalizable to any type of skill relationship.

case 'user-skill':
return _matchWithRelationship(item, skill, relationship, 'user');
default:
return undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what to return for default here.

function _matchForModel(model, item, skill, relationship) {
switch(model) {
case 'user-skill':
return _matchWithRelationship(item, skill, relationship, 'user');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This switch was best way I could think of. Would appreciate other suggestions.

get
} = Ember;

let skillsList = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure of a better convention here for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I love that this is split out into a regular module, rather than a mixin/service.

As for the conventions, did you mean you are not sure if you should be exporting just an object literal? For this use case, where you are exporting 2 functions, I don't really see a problem with it.

you could export them both as named exports and let things that are importing it choose what they import. Or even make the default export be an object literal of the two functions still.

@@ -12,15 +13,13 @@ export default Component.extend({
tagName: 'li',

matched: notEmpty('userSkill'),
userSkills: service(),
userSkillsList: service(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you look into seeing if we can inject the type of skills list this is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you said earlier, I think we'll loop back to this once we have to expand out to other cases.

Copy link
Contributor

@WenInCode WenInCode left a comment

Choose a reason for hiding this comment

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

@joshsmith I left a few small comments. Other than those I like this change.


contains(skill) {
let userSkills = get(this, 'userSkills');
return skillsList.contains(userSkills, skill);
Copy link
Contributor

Choose a reason for hiding this comment

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

Has contains been deprecated in favour for Enumerable#includes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, it has. This contains is kind of a custom thing. It's really doing array-like operations on something that's not an array. Maybe that's confusing?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah yes - I definitely read this as if it was Enumerable#contains at first. But that makes sense now.

get
} = Ember;

let skillsList = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I love that this is split out into a regular module, rather than a mixin/service.

As for the conventions, did you mean you are not sure if you should be exporting just an object literal? For this use case, where you are exporting 2 functions, I don't really see a problem with it.

you could export them both as named exports and let things that are importing it choose what they import. Or even make the default export be an object literal of the two functions still.

function _matchForModel(model, item, skill, relationship) {
switch (model) {
case 'user-skill':
return _matchWithRelationship(item, skill, relationship, 'user');
Copy link
Contributor

Choose a reason for hiding this comment

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

@joshsmith I am not sure what the plan is down the line, or if the other model types would leverage the same _matchWithRelationship function. If they did you could do a mapping object for relationship name. Otherwise, this seems like a valid use-case for a switch statement.

return (itemRelationshipId === relationshipId) && (itemSkillId === skillId);
}

export default skillsList;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any chance we can add some documentation around this module? I'm a big fan of documentation in util modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. May want to add some unit tests for this, too.

Copy link
Contributor

@WenInCode WenInCode left a comment

Choose a reason for hiding this comment

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

LGTM -- some things brought up here will be added to follow-up issues

@joshsmith joshsmith merged commit e97717a into develop Feb 4, 2017
@joshsmith joshsmith deleted the refactor-user-skills-input branch February 4, 2017 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants