|
662 | 662 | }
|
663 | 663 | };
|
664 | 664 |
|
665 |
| - function PathObserver(object, path, callback, target, valueFn, setValueFn) { |
| 665 | + function PathObserver(object, path, callback, target, transformFn, |
| 666 | + setValueFn) { |
666 | 667 | var path = path instanceof Path ? path : getPath(path);
|
667 | 668 | if (!path || !path.length || !isObject(object)) {
|
668 | 669 | this.value_ = path ? path.getValueFrom(object) : undefined;
|
669 |
| - this.value = valueFn ? valueFn(this.value_) : this.value_; |
| 670 | + this.value = transformFn ? transformFn(this.value_) : this.value_; |
670 | 671 | this.closed = true;
|
671 | 672 | return;
|
672 | 673 | }
|
673 | 674 |
|
674 | 675 | Observer.call(this, object, callback, target);
|
675 |
| - this.valueFn = valueFn; |
| 676 | + this.transformFn = transformFn; |
676 | 677 | this.setValueFn = setValueFn;
|
677 | 678 | this.path = path;
|
678 | 679 |
|
|
712 | 713 | if (areSameValue(this.value_, this.oldValue_))
|
713 | 714 | return false;
|
714 | 715 |
|
715 |
| - this.value = this.valueFn ? this.valueFn(this.value_) : this.value_; |
| 716 | + this.value = this.transformFn ? this.transformFn(this.value_) |
| 717 | + : this.value_; |
716 | 718 | this.reportArgs = [this.value, this.oldValue];
|
717 | 719 | return true;
|
718 | 720 | },
|
|
723 | 725 | this.observedSet.reset();
|
724 | 726 |
|
725 | 727 | this.value_ = this.path.getValueFrom(this.object, this.observedSet);
|
726 |
| - this.value = this.valueFn ? this.valueFn(this.value_) : this.value_; |
| 728 | + this.value = this.transformFn ? this.transformFn(this.value_) |
| 729 | + : this.value_; |
727 | 730 |
|
728 | 731 | if (this.observedSet)
|
729 | 732 | this.observedSet.cleanup();
|
|
734 | 737 | },
|
735 | 738 |
|
736 | 739 | setValue: function(newValue) {
|
737 |
| - if (!this.path) |
738 |
| - return; |
739 |
| - if (typeof this.setValueFn === 'function') |
740 |
| - newValue = this.setValueFn(newValue); |
741 |
| - this.path.setValueFrom(this.object, newValue); |
| 740 | + if (this.setValueFn) |
| 741 | + this.setValueFn(newValue); |
| 742 | + else if (this.path) |
| 743 | + this.path.setValueFrom(this.object, newValue); |
742 | 744 | }
|
743 | 745 | });
|
744 | 746 |
|
745 |
| - function CompoundPathObserver(callback, target, valueFn) { |
| 747 | + function CompoundPathObserver(callback, target, transformFn, setValueFn) { |
746 | 748 | Observer.call(this, undefined, callback, target);
|
747 |
| - this.valueFn = valueFn; |
| 749 | + this.transformFn = transformFn; |
| 750 | + this.setValueFn = setValueFn; |
748 | 751 |
|
749 | 752 | this.observed = [];
|
750 | 753 | this.values = [];
|
|
790 | 793 | var value = path.getValueFrom(object, this.observedSet);
|
791 | 794 | var oldValue = this.values[i/2];
|
792 | 795 | if (!areSameValue(value, oldValue)) {
|
793 |
| - if (!anyChanged && !this.valueFn) { |
| 796 | + if (!anyChanged && !this.transformFn) { |
794 | 797 | this.oldValues = this.oldValues || [];
|
795 | 798 | this.changeFlags = this.changeFlags || [];
|
796 | 799 | for (var j = 0; j < this.values.length; j++) {
|
|
799 | 802 | }
|
800 | 803 | }
|
801 | 804 |
|
802 |
| - if (!this.valueFn) |
| 805 | + if (!this.transformFn) |
803 | 806 | this.changeFlags[i/2] = true;
|
804 | 807 |
|
805 | 808 | this.values[i/2] = value;
|
|
817 | 820 | if (!this.getValues())
|
818 | 821 | return;
|
819 | 822 |
|
820 |
| - if (this.valueFn) { |
821 |
| - this.value = this.valueFn(this.values); |
| 823 | + if (this.transformFn) { |
| 824 | + this.value = this.transformFn(this.values); |
822 | 825 |
|
823 | 826 | if (areSameValue(this.value, this.oldValue))
|
824 | 827 | return false;
|
|
835 | 838 | sync: function(hard) {
|
836 | 839 | if (hard) {
|
837 | 840 | this.getValues();
|
838 |
| - if (this.valueFn) |
839 |
| - this.value = this.valueFn(this.values); |
| 841 | + if (this.transformFn) |
| 842 | + this.value = this.transformFn(this.values); |
840 | 843 | }
|
841 | 844 |
|
842 |
| - if (this.valueFn) |
| 845 | + if (this.transformFn) |
843 | 846 | this.oldValue = this.value;
|
844 | 847 | },
|
845 | 848 |
|
|
0 commit comments