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

fix: prevent usage of deprecated Ember global #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
109 changes: 61 additions & 48 deletions addon/components/range-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,35 @@ import Component from '@ember/component';
import { run } from '@ember/runloop';
import { isEmpty } from '@ember/utils';
import { observer, computed } from '@ember/object';
import Ember from 'ember';
import noUiSlider from 'noUiSlider';

const {
Logger: { warn }
} = Ember;

export default Component.extend({
attributeBindings: ['disabledOrUndefined:disabled'],
slider: null,
start: undefined,
step: undefined,
margin: undefined,
padding: undefined,
limit: undefined,
pips: undefined,
animate: true,
snap: false,
connect: false,
disabled: false,
orientation: 'horizontal',
direction: 'ltr',
behaviour: 'tap',
tooltips: false,
multitouch: false,
keyboardSupport: true,
slider: null,
start: undefined,
step: undefined,
margin: undefined,
padding: undefined,
limit: undefined,
pips: undefined,
animate: true,
snap: false,
connect: false,
disabled: false,
orientation: 'horizontal',
direction: 'ltr',
behaviour: 'tap',
tooltips: false,
multitouch: false,
keyboardSupport: true,

min: 0,
max: 100,

range: computed('min', 'max', function() {
range: computed('min', 'max', function () {
return {
min: this.get('min'),
max: this.get('max')
max: this.get('max'),
};
}),

Expand All @@ -50,10 +45,10 @@ export default Component.extend({
return +value;
},

format: computed('formatTo', 'formatFrom', function() {
format: computed('formatTo', 'formatFrom', function () {
return {
to: this.get('formatTo'),
from: this.get('formatFrom')
from: this.get('formatFrom'),
};
}),

Expand All @@ -65,13 +60,25 @@ export default Component.extend({
let element = this.get('element');
let { noUiSlider: slider } = element;
let properties = this.getProperties(
'start', 'step', 'margin', 'padding',
'limit', 'range', 'connect',
'orientation', 'direction',
'behaviour', 'animate', 'snap',
'pips', 'format', 'tooltips',
'multitouch', 'cssPrefix',
'cssClasses', 'keyboardSupport'
'start',
'step',
'margin',
'padding',
'limit',
'range',
'connect',
'orientation',
'direction',
'behaviour',
'animate',
'snap',
'pips',
'format',
'tooltips',
'multitouch',
'cssPrefix',
'cssClasses',
'keyboardSupport'
);
let sliderEvents = A(['change', 'set', 'slide', 'update']);

Expand All @@ -83,24 +90,24 @@ export default Component.extend({
try {
slider = noUiSlider.create(element, properties, true);
} catch (err) {
warn(`[ember-cli-nouislider]: ${err}`);
console.warn(`[ember-cli-nouislider]: ${err}`);
}

this.slider = slider;

sliderEvents.forEach(event => {
sliderEvents.forEach((event) => {
const eventActionName = `on-${event}`;

if (!isEmpty(this.get(eventActionName))) {
slider.on(event, () => {
run(this, function() {
run(this, function () {
const val = this.get('slider').get();
const action = this.get(eventActionName);

if (typeof(action) === 'string') {
if (typeof action === 'string') {
// Note that `sendAction` is deprecated and this will trigger a deprecation message.
this.sendAction(eventActionName, val);
} else if (typeof(action) === 'function') {
} else if (typeof action === 'function') {
action(val);
}
});
Expand All @@ -109,20 +116,20 @@ export default Component.extend({
});

slider.on('start', () => {
run(this, function() {
run(this, function () {
this.onStart();
if (!isEmpty(this.get(`on-start`))) {
let val = this.get("slider").get();
let val = this.get('slider').get();
this.sendAction(`on-start`, val);
}
});
});

slider.on('end', () => {
run(this, function() {
run(this, function () {
this.onEnd();
if (!isEmpty(this.get(`on-end`))) {
let val = this.get("slider").get();
let val = this.get('slider').get();
this.sendAction(`on-end`, val);
}
});
Expand All @@ -144,9 +151,15 @@ export default Component.extend({
update() {
let { slider } = this;
let properties = this.getProperties(
'margin', 'limit', 'step',
'range', 'animate', 'snap',
'start', 'padding', 'keyboardSupport'
'margin',
'limit',
'step',
'range',
'animate',
'snap',
'start',
'padding',
'keyboardSupport'
);

if (slider) {
Expand All @@ -167,7 +180,7 @@ export default Component.extend({
slider.destroy();
},

setValue: observer('start', function() {
setValue: observer('start', function () {
let { slider } = this;

if (slider && !this.sliding) {
Expand All @@ -177,10 +190,10 @@ export default Component.extend({
}),

// disabled can't be just `false` - this leads to an attribute of disabled="false"
disabledOrUndefined: computed('disabled', function() {
disabledOrUndefined: computed('disabled', function () {
if (this.get('disabled')) {
return true;
}
return undefined;
})
}),
});