Skip to content

Commit

Permalink
moar!
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Jun 25, 2015
1 parent 1c50b17 commit 61680ca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/ember-runtime/lib/mixins/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export function arrayContentDidChange(array, startIdx, removeAmt, addAmt) {
adding = addAmt;
}

propertyDidChange(array, '[]');
propertyDidChange(array, 'length');
// TODO: something something
// array.enumerableContentDidChange(removeAmt, adding);
sendEvent(array, '@array:change', [array, startIdx, removeAmt, addAmt]);
Expand Down Expand Up @@ -110,6 +112,8 @@ export function arrayContentWillChange(array, startIdx, removeAmt, addAmt) {
removing = removeAmt;
}

propertyWillChange(array, '[]');
propertyWillChange(array, 'length');
// TODO: can we kill these?
//enumerableContentWillChange(array, removing, addAmt);
}
Expand Down
1 change: 1 addition & 0 deletions packages/ember-runtime/lib/system/native_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Observable from 'ember-runtime/mixins/observable';
import Copyable from 'ember-runtime/mixins/copyable';
import { FROZEN_ERROR } from 'ember-runtime/mixins/freezable';
import copy from 'ember-runtime/copy';

export function replace(array, index, amt, objects) {
if (this.isFrozen) {
throw FROZEN_ERROR;
Expand Down
24 changes: 21 additions & 3 deletions packages/ember-views/lib/views/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,26 @@ import { A as emberA } from 'ember-runtime/system/native_array';
import { observer } from 'ember-metal/mixin';
import { defineProperty } from 'ember-metal/properties';
import { objectAt } from 'ember-runtime/mixins/array';

import htmlbarsTemplate from 'ember-htmlbars/templates/select';
import selectOptionDefaultTemplate from 'ember-htmlbars/templates/select-option';
import selectOptgroupDefaultTemplate from 'ember-htmlbars/templates/select-optgroup';

function find(obj, callback, target) {
if (obj.find) { return obj.find(callback, target); }

if (!Array.isArray(obj)) { throw new TypeError('TODO: GOOD ERROR!!'); }

var result = [];
for (let i = 0; i < obj.length; i++) {
let entry = obj[i];
if (callback.call(target, entry, i, obj)) {
result.push(entry);
}
}

return result;

}
var defaultTemplate = htmlbarsTemplate;

var SelectOption = View.extend({
Expand Down Expand Up @@ -535,7 +550,7 @@ var Select = View.extend({
var selection;

if (value !== selectedValue) {
selection = content ? content.find(function(obj) {
selection = content ? find(content, obj => {
return value === (valuePath ? get(obj, valuePath) : obj);
}) : null;

Expand Down Expand Up @@ -595,7 +610,10 @@ var Select = View.extend({
var selectedIndexes = options.map(function() {
return this.index - offset;
});
var newSelection = content.objectsAt([].slice.call(selectedIndexes));

var newSelection = [].slice.call(selectedIndexes).map((index) => {
return objectAt(content, index);
});

if (isArray(selection)) {
replace(selection, 0, get(selection, 'length'), newSelection);
Expand Down

0 comments on commit 61680ca

Please sign in to comment.