Skip to content

Commit

Permalink
chore(modules) use module syntax for the addon
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbieTheWagner authored and kybishop committed Aug 20, 2017
1 parent e497b72 commit 8bc50eb
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 87 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ node_js:
- "4"

sudo: false
dist: trusty

addons:
chrome: stable

cache:
yarn: true
Expand Down
4 changes: 2 additions & 2 deletions addon/-debug/helpers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Ember from 'ember';
import { deprecate as emberDeprecate } from '@ember/application/deprecations';
import { warn as emberWarn } from '@ember/debug';

const {
warn: emberWarn,
deprecate: emberDeprecate,
Logger
} = Ember;

Expand Down
61 changes: 32 additions & 29 deletions addon/components/ember-attacher-inner.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Ember from 'ember';
import layout from '../templates/components/ember-attacher-inner';
import { cancel, debounce, later, next } from '@ember/runloop';
import { computed, observer } from '@ember/object';
import Component from '@ember/component';
import { assert } from '@ember/debug';
import { htmlSafe } from '@ember/string';
import layout from '../templates/components/ember-attacher-inner';

export default Ember.Component.extend({
export default Component.extend({
/**
* ================== PUBLIC CONFIG OPTIONS ==================
*/
Expand Down Expand Up @@ -54,7 +57,7 @@ export default Ember.Component.extend({
this._super(...arguments);

// The Popper does not exist until after the element has been inserted
Ember.run.next(() => {
next(() => {
this._addListenersForShowEvents();

if (this.get('isVisible') && this.get('_target')) {
Expand Down Expand Up @@ -118,16 +121,16 @@ export default Ember.Component.extend({
isVisible: false,
layout,

_animation: Ember.computed('animation', function() {
_animation: computed('animation', function() {
return `ember-attacher-${this.get('animation')}`;
}),
_hideOn: Ember.computed('hideOn', function() {
_hideOn: computed('hideOn', function() {
return this.get('hideOn').split(' ');
}),
_showOn: Ember.computed('showOn', function() {
_showOn: computed('showOn', function() {
return this.get('showOn').split(' ');
}),
_target: Ember.computed('target', function() {
_target: computed('target', function() {
const target = this.get('target');

let popperTarget;
Expand All @@ -141,7 +144,7 @@ export default Ember.Component.extend({
const nodes = document.querySelectorAll(target);

assert(`ember-attacher with target selector "${target}" found ${nodes.length}`
+ 'possible targets when there should be exactly 1', nodes.length === 1);
+ 'possible targets when there should be exactly 1', nodes.length === 1);

popperTarget = nodes[0];
}
Expand All @@ -151,18 +154,18 @@ export default Ember.Component.extend({

// The circle element needs a special duration that is slightly faster than the popper's
// transition, this prevents text from appearing outside the circle as it fills the background
circleTransitionDuration: Ember.computed('_transitionDuration', function() {
return Ember.String.htmlSafe(
`transition-duration: ${Math.round(this.get('_transitionDuration')/1.25)}ms`
circleTransitionDuration: computed('_transitionDuration', function() {
return htmlSafe(
`transition-duration: ${Math.round(this.get('_transitionDuration') / 1.25)}ms`
);
}),

_setIsVisibleAfterDelay(isVisible, delay) {
Ember.run.cancel(this._isVisibleTimeout);
cancel(this._isVisibleTimeout);

if (delay) {
this._isVisibleTimeout =
Ember.run.later(this, () => {
later(this, () => {
if (!this.isDestroyed && !this.isDestroying) {
this.set('isVisible', isVisible);
}
Expand All @@ -172,7 +175,7 @@ export default Ember.Component.extend({
}
},

_targetOrTriggersChanged: Ember.observer(
_targetOrTriggersChanged: observer(
'hideOn',
'showOn',
'target',
Expand All @@ -193,8 +196,8 @@ export default Ember.Component.extend({
*/

_showAfterDelay() {
Ember.run.cancel(this._delayedHide);
Ember.run.cancel(this._isVisibleTimeout);
cancel(this._delayedHide);
cancel(this._isVisibleTimeout);

// The attachment is already visible or the target has been destroyed
if (!this._isHidden || !this.get('_target')) {
Expand All @@ -205,13 +208,13 @@ export default Ember.Component.extend({

const showDelay = parseInt(this.get('showDelay'));

this._delayedShow = Ember.run.debounce(this, this._show, showDelay, !showDelay);
this._delayedShow = debounce(this, this._show, showDelay, !showDelay);
},

_show() {
// The target of interactive tooltips receive the 'active' class
if (this.get('interactive')) {
this.get('_target').classList.add('active')
this.get('_target').classList.add('active');
}

// Make the attachment visible immediately so transition animations can take place
Expand All @@ -224,7 +227,7 @@ export default Ember.Component.extend({
// If we start the animation immediately, the transition won't work because isVisible will
// turn on the same time as our show animation, and `display: none` => `display: anythingElse`
// is not transition-able
Ember.run.next(this, () => {
next(this, () => {
const showDuration = parseInt(this.get('showDuration'));

this.element.style.transitionDuration = `${showDuration}ms`;
Expand Down Expand Up @@ -286,17 +289,17 @@ export default Ember.Component.extend({
},

_debouncedHideIfMouseOutsideTargetOrAttachment(event) {
Ember.run.debounce(this, this._hideIfMouseOutsideTargetOrAttachment, event, 10)
debounce(this, this._hideIfMouseOutsideTargetOrAttachment, event, 10);
},

_hideIfMouseOutsideTargetOrAttachment(event) {
const target = this.get('_target');

// If cursor is not on the attachment or target, hide the element
if (!target.contains(event.target)
&& !(this.get('isOffset') && this._isCursorBetweenTargetAndAttachment(event))
// The ember-attacher-inner element is wrapped in the ember-attacher element
&& !this.element.parentNode.contains(event.target)) {
if (!target.contains(event.target)
&& !(this.get('isOffset') && this._isCursorBetweenTargetAndAttachment(event))
// The ember-attacher-inner element is wrapped in the ember-attacher element
&& !this.element.parentNode.contains(event.target)) {
// Remove this listener before hiding the attachment
document.removeEventListener('mousemove', this._hideIfMouseOutsideTargetOrAttachment);

Expand All @@ -307,7 +310,7 @@ export default Ember.Component.extend({
},

_isCursorBetweenTargetAndAttachment(event) {
const {clientX, clientY} = event;
const { clientX, clientY } = event;

const attachmentPosition = this.element.getBoundingClientRect();
const targetPosition = this.get('_target').getBoundingClientRect();
Expand Down Expand Up @@ -360,8 +363,8 @@ export default Ember.Component.extend({
*/

_hideAfterDelay() {
Ember.run.cancel(this._delayedShow);
Ember.run.cancel(this._isVisibleTimeout);
cancel(this._delayedShow);
cancel(this._isVisibleTimeout);

// The attachment is already hidden or the target was destroyed
if (this._isHidden || !this.get('_target')) {
Expand All @@ -370,7 +373,7 @@ export default Ember.Component.extend({

const hideDelay = parseInt(this.get('hideDelay'));

this._delayedHide = Ember.run.debounce(this, this._hide, hideDelay, !hideDelay);
this._delayedHide = debounce(this, this._hide, hideDelay, !hideDelay);
},

_hide() {
Expand Down
29 changes: 16 additions & 13 deletions addon/components/ember-attacher.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Ember from 'ember';
import Component from '@ember/component';
import { alias } from '@ember/object/computed';
import { computed } from '@ember/object';
import { getOwner } from '@ember/application';
import layout from '../templates/components/ember-attacher';
import { stripInProduction, warn } from 'ember-attacher/-debug/helpers';

const DEFAULTS = {
const DEFAULTS = {
animation: 'fill',
arrow: false,
flip: null,
Expand All @@ -19,18 +22,18 @@ const DEFAULTS = {
renderInPlace: false,
showDelay: 0,
showDuration: 300,
showOn: 'mouseenter focus',
}
showOn: 'mouseenter focus'
};

export default Ember.Component.extend({
export default Component.extend({
layout,

/**
* ================== PUBLIC CONFIG OPTIONS ==================
*/

animation: DEFAULTS.animation,
arrow: Ember.computed('animation', {
arrow: computed('animation', {
get() {
return DEFAULTS.arrow;
},
Expand All @@ -46,8 +49,8 @@ export default Ember.Component.extend({
}
}),
hideDelay: DEFAULTS.hideDelay,
hideDuration: DEFAULTS.hideDuration,
hideOn: DEFAULTS.hideOn,
hideDuration: DEFAULTS.hideDuration,
hideOn: DEFAULTS.hideOn,
interactive: DEFAULTS.interactive,
isOffset: DEFAULTS.isOffset,
isShown: DEFAULTS.isShown,
Expand All @@ -59,7 +62,7 @@ export default Ember.Component.extend({
showDelay: DEFAULTS.showDelay,
showDuration: DEFAULTS.showDuration,
showOn: DEFAULTS.showOn,
target: Ember.computed(function() {
target: computed(function() {
return (typeof FastBoot === 'undefined') ? this.element.parentNode : null;
}),

Expand All @@ -68,16 +71,16 @@ export default Ember.Component.extend({
*/

// Part of the Component superclass. isVisible == false sets 'display: none'
isVisible: Ember.computed.alias('renderInPlace'),
isVisible: alias('renderInPlace'),

_isShown: Ember.computed('isShown', function() {
_isShown: computed('isShown', function() {
return !!this.get('isShown');
}),

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

let options = Ember.getOwner(this).resolveRegistration('config:environment').emberAttacher;
let options = getOwner(this).resolveRegistration('config:environment').emberAttacher;

// If no emberAttacher hash was found, do nothing
if (options) {
Expand All @@ -98,7 +101,7 @@ export default Ember.Component.extend({
}
},

_modifiers: Ember.computed('arrow', 'flip', 'modifiers', function() {
_modifiers: computed('arrow', 'flip', 'modifiers', function() {
// Deep copy the modifiers since we might write to the provided hash
let modifiers = this.get('modifiers') ? JSON.parse(JSON.stringify(this.get('modifiers'))) : {};

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"deploy": "ember github-pages:commit --message \"Deploy gh-pages from commit $(git rev-parse HEAD)\"; git push; git checkout -"
},
"dependencies": {
"ember-cli-babel": "^6.3.0",
"ember-cli-babel": "^6.8.1",
"ember-cli-htmlbars": "^2.0.2",
"ember-cli-sass": "^7.0.0",
"ember-popper": "^0.5.0",
Expand All @@ -36,7 +36,6 @@
"@html-next/flexi-default-styles": "^2.0.1",
"@html-next/flexi-dsl": "^2.0.1",
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^3.0.0",
"ember-cli": "^2.14.1",
"ember-cli-dependency-checker": "^2.0.1",
"ember-cli-eslint": "^4.2.0",
Expand Down
13 changes: 10 additions & 3 deletions testem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ module.exports = {
test_page: 'tests/index.html?hidepassed',
disable_watching: true,
launch_in_ci: [
'PhantomJS'
'Chrome'
],
launch_in_dev: [
'PhantomJS',
'Chrome'
]
],
browser_args: {
Chrome: [
'--disable-gpu',
'--headless',
'--remote-debugging-port=9222',
'--window-size=1440,900'
]
}
};
6 changes: 2 additions & 4 deletions tests/dummy/app/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import Ember from 'ember';
import Application from '@ember/application';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

let App;

App = Ember.Application.extend({
const App = Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Resolver
Expand Down
18 changes: 8 additions & 10 deletions tests/dummy/app/components/attachment-example.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import Ember from 'ember';
import Component from '@ember/component';
import { computed } from '@ember/object';
import layout from '../templates/components/attachment-example';
import { inject as service } from '@ember/service';

export default Ember.Component.extend({
export default Component.extend({
layout,
popoverData: Ember.inject.service(),
tooltipData: Ember.inject.service(),
popoverData: service(),
tooltipData: service(),

animationOptions: [
'fade',
Expand All @@ -14,19 +16,15 @@ export default Ember.Component.extend({
'scale',
'shift'
],

hideOnOptions: ['click', 'mouseleave blur'],

isConfiguringTooltip: true,

placementOptions: ['bottom', 'left', 'right', 'top'],
showOnOptions: ['click', 'mouseenter focus'],

service: Ember.computed('isConfiguringTooltip', function() {
service: computed('isConfiguringTooltip', function() {
return this.get('isConfiguringTooltip') ? this.get('tooltipData') : this.get('popoverData');
}),

showOnOptions: ['click', 'mouseenter focus'],

actions: {
toggleArrow() {
this.get('service').toggleProperty('arrow');
Expand Down
4 changes: 2 additions & 2 deletions tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Ember from 'ember';
import Controller from '@ember/controller';

export default Ember.Controller.extend({
export default Controller.extend({
});
4 changes: 2 additions & 2 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ember from 'ember';
import EmberRouter from '@ember/routing/router';
import config from './config/environment';

const Router = Ember.Router.extend({
const Router = EmberRouter.extend({
location: config.locationType,
rootURL: config.rootURL
});
Expand Down
4 changes: 2 additions & 2 deletions tests/dummy/app/services/popover-data.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Ember from 'ember';
import Service from '@ember/service';

export default Ember.Service.extend({
export default Service.extend({
animation: 'shift',
arrow: false,
hideDelay: 0,
Expand Down
Loading

0 comments on commit 8bc50eb

Please sign in to comment.