createPropertyDescriptor.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*global define*/
  2. define([
  3. '../Core/defaultValue',
  4. '../Core/defined'
  5. ], function(
  6. defaultValue,
  7. defined) {
  8. "use strict";
  9. function createProperty(name, privateName, subscriptionName, configurable) {
  10. return {
  11. configurable : configurable,
  12. get : function() {
  13. return this[privateName];
  14. },
  15. set : function(value) {
  16. var oldValue = this[privateName];
  17. var subscription = this[subscriptionName];
  18. if (defined(subscription)) {
  19. subscription();
  20. this[subscriptionName] = undefined;
  21. }
  22. if (oldValue !== value) {
  23. this[privateName] = value;
  24. this._definitionChanged.raiseEvent(this, name, value, oldValue);
  25. }
  26. if (defined(value) && defined(value.definitionChanged)) {
  27. this[subscriptionName] = value.definitionChanged.addEventListener(function() {
  28. this._definitionChanged.raiseEvent(this, name, value, value);
  29. }, this);
  30. }
  31. }
  32. };
  33. }
  34. /**
  35. * Used to consistently define all DataSources graphics objects.
  36. * This is broken into two functions because the Chrome profiler does a better
  37. * job of optimizing lookups if it notices that the string is constant throughout the function.
  38. * @private
  39. */
  40. function createPropertyDescriptor(name, configurable) {
  41. return createProperty(name, '_' + name, '_' + name + 'Subscription', defaultValue(configurable, false));
  42. }
  43. return createPropertyDescriptor;
  44. });