2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2014-06-15 00:45:50 +04: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-25 01:09:50 +04:00
|
|
|
* @param {*} upstream
|
|
|
|
* @param {function} transform a function to transform the **upstream** value.
|
2014-06-15 00:45:50 +04:00
|
|
|
*/
|
2015-08-19 14:55:40 +03:00
|
|
|
export default function (upstream, transform) {
|
2014-06-15 00:45:50 +04:00
|
|
|
if (typeof transform !== 'function') {
|
2014-10-25 01:09:50 +04:00
|
|
|
// default to the identity function
|
2014-06-15 00:45:50 +04:00
|
|
|
transform = function (value) { return value; };
|
|
|
|
}
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2015-06-03 05:56:42 +03:00
|
|
|
return Ember.computed(upstream, {
|
|
|
|
get: function () {
|
|
|
|
return transform(this.get(upstream));
|
|
|
|
},
|
|
|
|
set: function (key, value) {
|
|
|
|
return value;
|
|
|
|
}
|
2014-07-30 05:57:19 +04:00
|
|
|
});
|
2015-08-19 14:55:40 +03:00
|
|
|
}
|