subscribeAndEvaluate.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. /*global define*/
  2. define([
  3. '../ThirdParty/knockout'
  4. ], function(
  5. knockout) {
  6. "use strict";
  7. /**
  8. * Subscribe to a Knockout observable ES5 property, and immediately fire
  9. * the callback with the current value of the property.
  10. *
  11. * @private
  12. *
  13. * @exports subscribeAndEvaluate
  14. *
  15. * @param {Object} owner The object containing the observable property.
  16. * @param {String} observablePropertyName The name of the observable property.
  17. * @param {Function} callback The callback function.
  18. * @param {Object} [target] The value of this in the callback function.
  19. * @param {String} [event='change'] The name of the event to receive notification for.
  20. * @returns The subscription object from Knockout which can be used to dispose the subscription later.
  21. */
  22. var subscribeAndEvaluate = function(owner, observablePropertyName, callback, target, event) {
  23. callback.call(target, owner[observablePropertyName]);
  24. return knockout.getObservable(owner, observablePropertyName).subscribe(callback, target, event);
  25. };
  26. return subscribeAndEvaluate;
  27. });