Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

Update JS to ES6 #660

Merged
merged 1 commit into from
Oct 20, 2017
Merged

Update JS to ES6 #660

merged 1 commit into from
Oct 20, 2017

Conversation

anselmbradford
Copy link
Member

Changes

  • Update cf-tables and cf-expandables to ES6 syntax.
  • Remove "Organism" suffix from table and expandable names (the type should be able to be looked up through the prototype, also this is obfuscated through minification anyway).
  • Prefer named methods vs anonymous functions.

Testing

const contains = domClassList.contains;
const addClass = domClassList.addClass;
const closest = require( 'cf-atomic-component/src/utilities/dom-closest' ).closest;
const removeClass = domClassList.removeClass;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicky, but lets group all the domClassList child vars together.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

this.transition.toggleExpandable();
this.toggleTargetState( this.ui.target );
},
transition: null,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these values down to L:43 be left aligned to stay consistent with the objects above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

function initialize() {
const customClasses = {
BASE_CLASS: 'o-expandable_content__transition',
EXPANDED: 'o-expandable_content__expanded',
Copy link
Contributor

Choose a reason for hiding this comment

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

EXPANDED and COLLAPSED are defined in the classes object. Should they be saved as constants at the top of the file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, that's a good point! Let's revisit that in #665, lest I break some existing functionality here.

const transition = new ExpandableTransition( this.ui.content, customClasses );
this.transition = transition.init();

const groupElement = closest( this.ui.target, '.' + this.classes.groupAccordion );
Copy link
Contributor

Choose a reason for hiding this comment

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

Outside the scope, but if we're deciding all expandables should be in a group organism, should we target and initialize on the group instead of the individual expandables? It might make this a bit more efficient because we wouldn't have to lookup the group a whole bunch of times.

Copy link
Member Author

Choose a reason for hiding this comment

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

Totally! I think everything would move to the group so we could eliminate the closest helper. (Related issue #665)

};
target = closest( event.target, 'tr' );
const link = target.querySelector( 'a' );
if ( link ) window.location = link.getAttribute( 'href' );
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be wrapped in curly braces to match the return on L:31

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

* Function used to create computed and triggered properties.
*/
function initialize() {
this.sortClass = UNDEFINED;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be part of a customClasses object like in the Expandables code instead of properties?

Copy link
Member Author

Choose a reason for hiding this comment

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

This looks like a different use case. In Expandables there's a set of class names that are assigned to constants that are only used inside the initialize method, so their scope is fine. In this case, sortClass is not constant and is used across methods, so is assigned as a property to share between methods. Personally I prefer not to expose anything publicly that is not needed in the public API, lest it leads to unintended implementations, so if sortClass could be internal that would be better (such as by moving it's location above the scope of the TableSortable object), but I don't think that's currently possible here as the methods here get added to instances of the Table organism, so that if sortClass was in a higher scope it would then become shared among all Table organisms using the TableSortable modifier. Is that right @sebworks?

Copy link
Contributor

Choose a reason for hiding this comment

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

yep, that is correct @anselmbradford

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, sidenote that my renaming these capitalized like they are classes when they're not instantiating new instances is possibly misleading.

Copy link
Contributor

@sebworks sebworks left a comment

Choose a reason for hiding this comment

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

nice work

@anselmbradford anselmbradford merged commit e614de9 into canary Oct 20, 2017
@anselmbradford anselmbradford deleted the es6_update branch October 20, 2017 19:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants