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

Prefer const over let & update variables names #208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions addon/-private/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,30 @@ export default class State extends EmberObject {

@computed('animation', 'itemAnimation', 'customAnimation')
get styles() {
let animation = this.animation;
let itemAnimation = this.itemAnimation;
let customAnimation = this.customAnimation;
const { animation, itemAnimation, customAnimation } = this;

return getAnimation(customAnimation || animation, itemAnimation).create();
}

@action
openMenu(e) {
e?.stopPropagation?.();
openMenu(event) {
event?.stopPropagation?.();
if (!this.locked) {
this.open = true;
}
}

@action
closeMenu(e) {
e?.stopPropagation?.();
closeMenu(event) {
event?.stopPropagation?.();
if (!this.locked) {
this.open = false;
}
}

@action
toggleMenu(e) {
e?.stopPropagation?.();
toggleMenu(event) {
event?.stopPropagation?.();
if (!this.locked) {
this.open = !this.open;
}
Expand Down
26 changes: 12 additions & 14 deletions addon/components/burger-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,33 @@ export default Component.extend(SwipeSupportMixin, {
style: computedStyleFor('container').readOnly(),

animationClass: computed('state.styles.animation', function () {
let animation = this.get('state.styles.animation');
const animation = this.get('state.styles.animation');
return animation ? `bm--${animation}` : '';
}).readOnly(),

itemAnimationClass: computed('state.styles.itemAnimation', function () {
let itemAnimation = this.get('state.styles.itemAnimation');
const itemAnimation = this.get('state.styles.itemAnimation');
return itemAnimation ? `bm-item--${itemAnimation}` : '';
}).readOnly(),

init() {
this._super(...arguments);

this.onClick = (e) => {
this.onClick = (event) => {
if (this.dismissOnClick) {
let elementId = this.elementId;
const { elementId } = this;
// Close the menu if clicked outside of it
if (!e.target.closest(`#${elementId} .bm-menu`)) {
if (!event.target.closest(`#${elementId} .bm-menu`)) {
this.get('state').closeMenu();
}
}
};

this.onKeyup = (e) => {
if (this.dismissOnEsc) {
if (e.keyCode === 27) {
this.get('state').closeMenu();
}
this.onKeyup = (event) => {
const escapeKeyPressed = event.keyCode === 27;

if (this.dismissOnEsc && escapeKeyPressed) {
this.get('state').closeMenu();
}
};

Expand Down Expand Up @@ -99,10 +99,8 @@ export default Component.extend(SwipeSupportMixin, {
},

onSwipe(direction, target) {
let position = this.position;
let open = this.open;
let gesturesEnabled = this.gesturesEnabled;
let isMenuSwipe = target.closest('.bm-menu');
const { position, open, gesturesEnabled } = this;
const isMenuSwipe = target.closest('.bm-menu');

if (!gesturesEnabled) {
return;
Expand Down
6 changes: 3 additions & 3 deletions addon/computed/style-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { computed } from '@ember/object';

export default function computedStyleFor(type) {
return computed('state.{styles,open,width,position}', 'index', function () {
let state = this.state;
let args = state.getProperties(['open', 'width', 'position']);
const { state, index } = this;
const args = state.getProperties(['open', 'width', 'position']);

if (type === 'menuItem') {
args.index = this.index;
args.index = index;
}

return state.get('styles').generateCSSFor(type, args);
Expand Down
30 changes: 12 additions & 18 deletions addon/mixins/swipe-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,29 @@ export default Mixin.create({

onSwipe(/* direction, target */) {},

touchStart(e) {
touchStart(event) {
this._super(...arguments);

// jscs:disable
let touch = e.touches[0];
// jscs:enable
const { pageX, pageY } = event.touches[0];

meta = {
target: e.target,
target: event.target,
start: {
x: touch.pageX,
y: touch.pageY,
x: pageX,
y: pageY,
time: new Date().getTime(),
},
};
},

touchMove(e) {
touchMove({ touches = [] }) {
this._super(...arguments);

// jscs:disable
let touch = e.touches[0];
// jscs:enable
const { pageX, pageY } = touches[0];

meta.differences = {
x: touch.pageX - meta.start.x,
y: touch.pageY - meta.start.y,
x: pageX - meta.start.x,
y: pageY - meta.start.y,
};

// Compute swipe direction
Expand All @@ -46,17 +42,15 @@ export default Mixin.create({
}

// A valid swipe event uses only one finger
if (e.touches.length > 1) {
if (touches.length > 1) {
meta.isInvalid = true;
}
},

touchEnd() {
this._super(...arguments);

let minSwipeDistance = this.minSwipeDistance;
let maxSwipeTime = this.maxSwipeTime;
let elapsedTime = new Date().getTime() - meta.start.time;
const { minSwipeDistance, maxSwipeTime } = this;
const elapsedTime = new Date().getTime() - meta.start.time;

if (
meta.isHorizontal &&
Expand Down
8 changes: 4 additions & 4 deletions addon/utils/css-stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function cssStringify(hash = {}) {
return htmlSafe(
Object.keys(hash)
.reduce((css, key) => {
let value = hash[key];
const value = hash[key];

if (!isEmpty(value)) {
css = css.concat(buildProp(key, value));
Expand All @@ -33,11 +33,11 @@ export default function cssStringify(hash = {}) {

function buildProp(key, value) {
key = dasherize(key);
let css = [`${key}: ${value}`];
const css = [`${key}: ${value}`];

if (PREFIXED_PROPS.indexOf(key) > -1) {
PREFIXES.forEach((p) => {
css.push(`-${p}-${key}: ${value}`);
PREFIXES.forEach((prefix) => {
css.push(`-${prefix}-${key}: ${value}`);
});
}

Expand Down