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

Clean up some Glimmer deprecations #33

Merged
10 changes: 6 additions & 4 deletions addon/components/x-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ export default Ember.Component.extend({
didInsertElement: function() {
this._super.apply(this, arguments);

var select = this.nearestOfType(XSelectComponent);
Ember.assert("x-option component declared without enclosing x-select", !!select);
this.set('select', select);
select.registerOption(this);
Ember.run.scheduleOnce('afterRender', () => {
var select = this.nearestOfType(XSelectComponent);
Ember.assert("x-option component declared without enclosing x-select", !!select);
this.set('select', select);
select.registerOption(this);
});
},

/**
Expand Down
48 changes: 11 additions & 37 deletions addon/components/x-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var isArray = Ember.isArray;
export default Ember.Component.extend({
tagName: "select",
classNameBindings: [":x-select"],
attributeBindings: ['disabled', 'tabindex', 'multiple', 'name', 'autofocus', 'form', 'required', 'size'],
attributeBindings: ['disabled', 'tabindex', 'multiple', 'name', 'autofocus', 'required', 'size'],

/**
* Bound to the `disabled` attribute on the native <select> tag.
Expand Down Expand Up @@ -129,37 +129,23 @@ export default Ember.Component.extend({
return Ember.A();
}),

/**
* Listen for change events on the native <select> element, which
* indicates that the user has chosen a new option from the
* dropdown. If there is an associated `x-option` component that is
* selected, then the overall value of `x-select` becomes the value
* of that option.
*
* @override
*/
didInsertElement: function() {
this._super.apply(this, arguments);

this.$().on('change', Ember.run.bind(this, function() {
this._contentDidChange();
}));
},
_setFormAttribute: Ember.on('didRender', function() {
this.$().attr('form', this.get('form'));
}),

/**
* Triggers an update of the selected options.
* Observing `content` ensures that if an element is removed that
* is also part of the selection, selection is cleared.
*
* @private
* When the select DOM event fires on the element, trigger the
* component's action with the current value.
*/
_contentDidChange: Ember.observer('content.@each', function() {
change() {
if (this.get('multiple')) {
this._updateValueMultiple();
} else {
this._updateValueSingle();
}
}),

this.sendAction('action', this.get('value'), this);
},

/**
* Updates `value` with the object associated with the selected option tag
Expand All @@ -174,7 +160,7 @@ export default Ember.Component.extend({
if (option) {
this.set('value', option.get('value'));
} else {
this.set('value', undefined);
this.set('value', null);
}
},

Expand All @@ -195,7 +181,6 @@ export default Ember.Component.extend({
} else {
this.set('value', newValues);
}
this.raiseAction();
},

/**
Expand All @@ -204,21 +189,10 @@ export default Ember.Component.extend({
willDestroyElement: function() {
this._super.apply(this, arguments);

this.$().off('change');
// might be overkill, but make sure options can get gc'd
this.get('options').clear();
},

/**
* XSelect supports both two-way binding as well as an action. Observe the
* `value` property, and when it changes, raise that as an action.
*
* @private
*/
raiseAction: Ember.observer('value', function() {
this.sendAction('action', this.get('value'), this);
}),

/**
* If this is a multi-select, and the value is not an array, that
* probably indicates a misconfiguration somewhere, so we error out.
Expand Down
2 changes: 1 addition & 1 deletion app/templates/components/x-select.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if template}}
{{#if hasBlock}}
{{yield}}
{{else}}
{{#if placeholder}}
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "emberx-select",
"dependencies": {
"jquery": "^1.11.1",
"ember": "1.10.0",
"ember": "1.13.2",
"ember-data": "1.0.0-beta.15",
"ember-resolver": "~0.1.12",
"loader.js": "ember-cli/loader.js#3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"devDependencies": {
"broccoli-asset-rev": "2.0.6",
"ember-cli": "0.2.7",
"ember-cli-app-version": "0.3.2",
"ember-cli-app-version": "0.4.0",
"ember-cli-content-security-policy": "0.3.0",
"ember-cli-dependency-checker": "0.0.8",
"ember-cli-htmlbars": "0.7.4",
Expand Down
3 changes: 2 additions & 1 deletion tests/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"andThen",
"currentURL",
"currentPath",
"currentRouteName"
"currentRouteName",
"getComponentById"
],
"node": false,
"browser": false,
Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/x-select-multiple-blockless-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { bastion, stanley, charles } from 'dummy/mixins/folks';

var App;

describe('XSelect: Multiple Selection', function() {
describe('XSelect: Multiple Selection (Blockless)', function() {
var component, controller;
beforeEach(function() {
App = startApp();
visit("/blockless-multiple");
});
beforeEach(function() {
var el = Ember.$('select');
component = Ember.View.views[el.attr('id')];
component = getComponentById(el.attr('id'));
this.$ = function() {
return component.$.apply(component, arguments);
};
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/x-select-multiple-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('XSelect: Multiple Selection', function() {
});
beforeEach(function() {
var el = Ember.$('select');
component = Ember.View.views[el.attr('id')];
component = getComponentById(el.attr('id'));
this.$ = function() {
return component.$.apply(component, arguments);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('XSelect: Single Selection Blockless w/ Option Value', function() {
});
beforeEach(function() {
var el = Ember.$('select');
component = Ember.View.views[el.attr('id')];
component = getComponentById(el.attr('id'));
this.$ = function() {
return component.$.apply(component, arguments);
};
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('XSelect: Single Selection Blockless w/ Option Value', function() {
this.$().prop('selectedIndex', 4).trigger('change');
});
it("has no value", function() {
expect(controller.get('tagged')).to.equal(undefined);
expect(controller.get('tagged')).to.equal(null);
});
});

Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/x-select-single-blockless-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('XSelect: Single Selection Blockless', function() {
});
beforeEach(function() {
var el = Ember.$('select');
component = Ember.View.views[el.attr('id')];
component = getComponentById(el.attr('id'));
this.$ = function() {
return component.$.apply(component, arguments);
};
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('XSelect: Single Selection Blockless', function() {
this.$().prop('selectedIndex', 4).trigger('change');
});
it("has no value", function() {
expect(controller.get('tagged')).to.equal(undefined);
expect(controller.get('tagged')).to.equal(null);
});
});

Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/x-select-single-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('XSelect: Single Selection', function() {
});
beforeEach(function() {
var el = Ember.$('select');
component = Ember.View.views[el.attr('id')];
component = getComponentById(el.attr('id'));
this.$ = function() {
return component.$.apply(component, arguments);
};
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('XSelect: Single Selection', function() {
this.$().prop('selectedIndex', 4).trigger('change');
});
it("has no value", function() {
expect(controller.get('tagged')).to.equal(undefined);
expect(controller.get('tagged')).to.equal(null);
});
});

Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Ember from 'ember';


export default Ember.ObjectController.extend({
export default Ember.Controller.extend({

});
2 changes: 1 addition & 1 deletion tests/dummy/app/controllers/blockless-multiple.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ember from 'ember';
import Folks from 'dummy/mixins/folks';

export default Ember.ObjectController.extend(Folks, {
export default Ember.Controller.extend(Folks, {
isDisabled: false,
actions: {
tagYouAreIt: function(object) {
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/controllers/blockless-single.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ember from 'ember';
import Folks from 'dummy/mixins/folks';

export default Ember.ObjectController.extend(Folks, {
export default Ember.Controller.extend(Folks, {
isDisabled: false,
actions: {
tagYouAreIt: function(object) {
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/controllers/multiple.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ember from 'ember';
import Folks from 'dummy/mixins/folks';

export default Ember.ObjectController.extend(Folks, {
export default Ember.Controller.extend(Folks, {
actions: {
selectionsChanged: function(selections) {
this.set('currentSelections', selections);
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/controllers/single.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ember from 'ember';
import Folks from 'dummy/mixins/folks';

export default Ember.ObjectController.extend(Folks, {
export default Ember.Controller.extend(Folks, {
isDisabled: false,
isRequired: false,
hasAutofocus: false,
Expand Down
4 changes: 2 additions & 2 deletions tests/dummy/app/templates/blockless-multiple.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
</p>
<p>Selected:</p>
<ul>
{{#each selection in model}}
{{#each model as |selection|}}
<li>{{selection.name}}</li>
{{else}}
<li>(None)</li>
{{/each}}
</ul>
<p>All options:</p>
<ul>
{{#each folk in folks}}
{{#each folks as |folk|}}
<li>{{folk.name}} - <a href="#" {{action "removeFolk" folk}}>Remove Folk</a></li>
{{else}}
<li>(None)</li>
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/blockless-single.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<p>Selected: {{it.name}}</p>
<p>All options:</p>
<ul>
{{#each folk in folks}}
{{#each folks as |folk|}}
<li>{{folk.name}} - <a href="#" {{action "removeFolk" folk}}>Remove Folk</a></li>
{{else}}
<li>(None)</li>
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/multiple.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</p>
<p>Selected:</p>
<ul>
{{#each selection in model}}
{{#each model as |selection|}}
<li>{{selection.name}}</li>
{{else}}
<li>(None)</li>
Expand Down
11 changes: 11 additions & 0 deletions tests/helpers/get-component-by-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Ember from "ember";

function getComponentById(app, id) {
return app.__container__.lookup('-view-registry:main')[id];
}

const customHelpers = (function() {
Ember.Test.registerHelper('getComponentById', getComponentById);
})();

export default customHelpers;
1 change: 1 addition & 0 deletions tests/helpers/start-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Ember from 'ember';
import Application from '../../app';
import Router from '../../router';
import config from '../../config/environment';
import getComponentById from './get-component-by-id';

export default function startApp(attrs) {
var application;
Expand Down