subscribeAndEvaluate.js 1013 B

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