Skip to content

Commit

Permalink
getValue refactor breaking change for people explicitly using it
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden committed Apr 25, 2017
1 parent 426827a commit 922fe7c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
7 changes: 2 additions & 5 deletions addon/-build-computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ function parseComputedArgs(args) {
};
}

function mapKeysToValues(keys, getValue, context) {
return keys.map(key => getValue(context, key));
}

function buildCallback(collapsedKeys, incomingCallback, getValue) {
let newCallback;

function createArgs(context) {
return mapKeysToValues(collapsedKeys, getValue, context);
let bundledKeys = collapsedKeys.map(key => ({ context, key }));
return bundledKeys.map(getValue);
}

if (typeof incomingCallback === 'function') {
Expand Down
4 changes: 2 additions & 2 deletions addon/create-class-computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default function(observerBools, macroGenerator) {
let mappedWithResolvedOberverKeys = mappedKeys.map((key, i) => {
let shouldObserve = observerBools[i];
if (shouldObserve) {
key = getValue(this, key);
key = getValue({ context: this, key });
}
return key;
});
Expand Down Expand Up @@ -116,7 +116,7 @@ export default function(observerBools, macroGenerator) {

let properties = collapsedKeys.reduce((properties, key, i) => {
if (typeof key !== 'string') {
properties[i.toString()] = getValue(this, key);
properties[i.toString()] = getValue({ context: this, key });
}
return properties;
}, {});
Expand Down
4 changes: 2 additions & 2 deletions addon/get-value-unsafe.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import getValue from './get-value';

export default function(context, key) {
let value = getValue(context, key);
export default function({ context, key }) {
let value = getValue({ context, key });
if (value !== undefined) {
return value;
}
Expand Down
2 changes: 1 addition & 1 deletion addon/get-value.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import get from 'ember-metal/get';
import isComputed from './is-computed';

export default function(context, key) {
export default function({ context, key }) {
if (isComputed(key)) {
return key._getter.call(context);
}
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/get-value-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module('Unit | get value');
testKey: 'test value'
};

let value = getValue(context, 'testKey');
let value = getValue({ context, key: 'testKey' });

assert.strictEqual(value, 'test value');
});
Expand All @@ -36,7 +36,7 @@ module('Unit | get value');
let callback = sinon.stub().returns('test value');
let key = computed(callback);

let value = getValue(context, key);
let value = getValue({ context, key });

assert.strictEqual(callback.thisValues[0], context);
assert.strictEqual(value, 'test value');
Expand All @@ -47,7 +47,7 @@ module('Unit | get value');
testKey: false
};

let value = getValue(context, 'testKey');
let value = getValue({ context, key: 'testKey' });

assert.strictEqual(value, false);
});
Expand All @@ -56,15 +56,15 @@ module('Unit | get value');
namedTest('getValue', 'returns undefined if property doesn\'t exist', function(assert) {
let context = {};

let value = getValue(context, 'testKey');
let value = getValue({ context, key: 'testKey' });

assert.strictEqual(value, undefined);
});

namedTest('getValueUnsafe', 'returns literal if property doesn\'t exist', function(assert) {
let context = {};

let value = getValueUnsafe(context, 'testKey');
let value = getValueUnsafe({ context, key: 'testKey' });

assert.strictEqual(value, 'testKey');
});

0 comments on commit 922fe7c

Please sign in to comment.