2015-02-12 21:22:32 -07:00
|
|
|
import Ember from 'ember';
|
2014-06-14 14:45:50 -06:00
|
|
|
/**
|
|
|
|
* Defines a property similarly to `Ember.computed.oneway`,
|
|
|
|
* save that while a `oneway` loses its binding upon being set,
|
|
|
|
* the `BoundOneWay` will continue to listen for upstream changes.
|
|
|
|
*
|
|
|
|
* This is an ideal tool for working with values inside of {{input}}
|
|
|
|
* elements.
|
2014-10-24 21:09:50 +00:00
|
|
|
* @param {*} upstream
|
|
|
|
* @param {function} transform a function to transform the **upstream** value.
|
2014-06-14 14:45:50 -06:00
|
|
|
*/
|
2015-08-19 12:55:40 +01:00
|
|
|
export default function (upstream, transform) {
|
2014-06-14 14:45:50 -06:00
|
|
|
if (typeof transform !== 'function') {
|
2014-10-24 21:09:50 +00:00
|
|
|
// default to the identity function
|
2014-06-14 14:45:50 -06:00
|
|
|
transform = function (value) { return value; };
|
|
|
|
}
|
2014-10-24 21:09:50 +00:00
|
|
|
|
2015-06-02 20:56:42 -06:00
|
|
|
return Ember.computed(upstream, {
|
|
|
|
get: function () {
|
|
|
|
return transform(this.get(upstream));
|
|
|
|
},
|
|
|
|
set: function (key, value) {
|
|
|
|
return value;
|
|
|
|
}
|
2014-07-29 19:57:19 -06:00
|
|
|
});
|
2015-08-19 12:55:40 +01:00
|
|
|
}
|