| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | 2 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 3 * This code may only be used under the BSD style license found at http://polyme
r.github.io/LICENSE.txt | 3 * This code may only be used under the BSD style license found at http://polyme
r.github.io/LICENSE.txt |
| 4 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.
txt | 4 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.
txt |
| 5 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.txt | 5 * The complete set of contributors may be found at http://polymer.github.io/CON
TRIBUTORS.txt |
| 6 * Code distributed by Google as part of the polymer project is also | 6 * Code distributed by Google as part of the polymer project is also |
| 7 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt | 7 * subject to an additional IP rights grant found at http://polymer.github.io/PA
TENTS.txt |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 (function(global) { | 10 (function(global) { |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 } | 383 } |
| 384 return obj; | 384 return obj; |
| 385 }, | 385 }, |
| 386 | 386 |
| 387 iterateObjects: function(obj, observe) { | 387 iterateObjects: function(obj, observe) { |
| 388 for (var i = 0; i < this.length; i++) { | 388 for (var i = 0; i < this.length; i++) { |
| 389 if (i) | 389 if (i) |
| 390 obj = obj[this[i - 1]]; | 390 obj = obj[this[i - 1]]; |
| 391 if (!isObject(obj)) | 391 if (!isObject(obj)) |
| 392 return; | 392 return; |
| 393 observe(obj, this[0]); | 393 observe(obj, this[i]); |
| 394 } | 394 } |
| 395 }, | 395 }, |
| 396 | 396 |
| 397 compiledGetValueFromFn: function() { | 397 compiledGetValueFromFn: function() { |
| 398 var str = ''; | 398 var str = ''; |
| 399 var pathString = 'obj'; | 399 var pathString = 'obj'; |
| 400 str += 'if (obj != null'; | 400 str += 'if (obj != null'; |
| 401 var i = 0; | 401 var i = 0; |
| 402 var key; | 402 var key; |
| 403 for (; i < (this.length - 1); i++) { | 403 for (; i < (this.length - 1); i++) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 return false; | 504 return false; |
| 505 | 505 |
| 506 for (var i = 0; i < eomTasks.length; i++) { | 506 for (var i = 0; i < eomTasks.length; i++) { |
| 507 eomTasks[i](); | 507 eomTasks[i](); |
| 508 } | 508 } |
| 509 eomTasks.length = 0; | 509 eomTasks.length = 0; |
| 510 return true; | 510 return true; |
| 511 } | 511 } |
| 512 | 512 |
| 513 var runEOM = hasObserve ? (function(){ | 513 var runEOM = hasObserve ? (function(){ |
| 514 var eomObj = { pingPong: true }; | |
| 515 var eomRunScheduled = false; | |
| 516 | |
| 517 Object.observe(eomObj, function() { | |
| 518 runEOMTasks(); | |
| 519 eomRunScheduled = false; | |
| 520 }); | |
| 521 | |
| 522 return function(fn) { | 514 return function(fn) { |
| 523 eomTasks.push(fn); | 515 return Promise.resolve().then(fn); |
| 524 if (!eomRunScheduled) { | 516 } |
| 525 eomRunScheduled = true; | |
| 526 eomObj.pingPong = !eomObj.pingPong; | |
| 527 } | |
| 528 }; | |
| 529 })() : | 517 })() : |
| 530 (function() { | 518 (function() { |
| 531 return function(fn) { | 519 return function(fn) { |
| 532 eomTasks.push(fn); | 520 eomTasks.push(fn); |
| 533 }; | 521 }; |
| 534 })(); | 522 })(); |
| 535 | 523 |
| 536 var observedObjectCache = []; | 524 var observedObjectCache = []; |
| 537 | 525 |
| 538 function newObservedObject() { | 526 function newObservedObject() { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 | 644 |
| 657 for (var i = 0; i < observers.length; i++) { | 645 for (var i = 0; i < observers.length; i++) { |
| 658 observer = observers[i]; | 646 observer = observers[i]; |
| 659 if (observer.state_ == OPENED) { | 647 if (observer.state_ == OPENED) { |
| 660 observer.check_(); | 648 observer.check_(); |
| 661 } | 649 } |
| 662 } | 650 } |
| 663 } | 651 } |
| 664 | 652 |
| 665 var record = { | 653 var record = { |
| 666 object: undefined, | |
| 667 objects: objects, | 654 objects: objects, |
| 655 get rootObject() { return rootObj; }, |
| 656 set rootObject(value) { |
| 657 rootObj = value; |
| 658 rootObjProps = {}; |
| 659 }, |
| 668 open: function(obs, object) { | 660 open: function(obs, object) { |
| 669 if (!rootObj) { | |
| 670 rootObj = object; | |
| 671 rootObjProps = {}; | |
| 672 } | |
| 673 | |
| 674 observers.push(obs); | 661 observers.push(obs); |
| 675 observerCount++; | 662 observerCount++; |
| 676 obs.iterateObjects_(observe); | 663 obs.iterateObjects_(observe); |
| 677 }, | 664 }, |
| 678 close: function(obs) { | 665 close: function(obs) { |
| 679 observerCount--; | 666 observerCount--; |
| 680 if (observerCount > 0) { | 667 if (observerCount > 0) { |
| 681 return; | 668 return; |
| 682 } | 669 } |
| 683 | 670 |
| 684 for (var i = 0; i < objects.length; i++) { | 671 for (var i = 0; i < objects.length; i++) { |
| 685 Object.unobserve(objects[i], callback); | 672 Object.unobserve(objects[i], callback); |
| 686 Observer.unobservedCount++; | 673 Observer.unobservedCount++; |
| 687 } | 674 } |
| 688 | 675 |
| 689 observers.length = 0; | 676 observers.length = 0; |
| 690 objects.length = 0; | 677 objects.length = 0; |
| 691 rootObj = undefined; | 678 rootObj = undefined; |
| 692 rootObjProps = undefined; | 679 rootObjProps = undefined; |
| 693 observedSetCache.push(this); | 680 observedSetCache.push(this); |
| 694 } | 681 if (lastObservedSet === this) |
| 682 lastObservedSet = null; |
| 683 }, |
| 695 }; | 684 }; |
| 696 | 685 |
| 697 return record; | 686 return record; |
| 698 } | 687 } |
| 699 | 688 |
| 700 var lastObservedSet; | 689 var lastObservedSet; |
| 701 | 690 |
| 702 function getObservedSet(observer, obj) { | 691 function getObservedSet(observer, obj) { |
| 703 if (!lastObservedSet || lastObservedSet.object !== obj) { | 692 if (!lastObservedSet || lastObservedSet.rootObject !== obj) { |
| 704 lastObservedSet = observedSetCache.pop() || newObservedSet(); | 693 lastObservedSet = observedSetCache.pop() || newObservedSet(); |
| 705 lastObservedSet.object = obj; | 694 lastObservedSet.rootObject = obj; |
| 706 } | 695 } |
| 707 lastObservedSet.open(observer, obj); | 696 lastObservedSet.open(observer, obj); |
| 708 return lastObservedSet; | 697 return lastObservedSet; |
| 709 } | 698 } |
| 710 | 699 |
| 711 var UNOPENED = 0; | 700 var UNOPENED = 0; |
| 712 var OPENED = 1; | 701 var OPENED = 1; |
| 713 var CLOSED = 2; | 702 var CLOSED = 2; |
| 714 var RESETTING = 3; | 703 var RESETTING = 3; |
| 715 | 704 |
| (...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 return | 1672 return |
| 1684 }; | 1673 }; |
| 1685 | 1674 |
| 1686 splices = splices.concat(calcSplices(array, splice.index, splice.index + s
plice.addedCount, | 1675 splices = splices.concat(calcSplices(array, splice.index, splice.index + s
plice.addedCount, |
| 1687 splice.removed, 0, splice.removed.len
gth)); | 1676 splice.removed, 0, splice.removed.len
gth)); |
| 1688 }); | 1677 }); |
| 1689 | 1678 |
| 1690 return splices; | 1679 return splices; |
| 1691 } | 1680 } |
| 1692 | 1681 |
| 1693 global.Observer = Observer; | 1682 // Export the observe-js object for **Node.js**, with |
| 1694 global.Observer.runEOM_ = runEOM; | 1683 // backwards-compatibility for the old `require()` API. If we're in |
| 1695 global.Observer.observerSentinel_ = observerSentinel; // for testing. | 1684 // the browser, export as a global object. |
| 1696 global.Observer.hasObjectObserve = hasObserve; | 1685 |
| 1697 global.ArrayObserver = ArrayObserver; | 1686 var expose = global; |
| 1698 global.ArrayObserver.calculateSplices = function(current, previous) { | 1687 |
| 1688 if (typeof exports !== 'undefined') { |
| 1689 if (typeof module !== 'undefined' && module.exports) { |
| 1690 expose = exports = module.exports; |
| 1691 } |
| 1692 expose = exports; |
| 1693 } |
| 1694 |
| 1695 expose.Observer = Observer; |
| 1696 expose.Observer.runEOM_ = runEOM; |
| 1697 expose.Observer.observerSentinel_ = observerSentinel; // for testing. |
| 1698 expose.Observer.hasObjectObserve = hasObserve; |
| 1699 expose.ArrayObserver = ArrayObserver; |
| 1700 expose.ArrayObserver.calculateSplices = function(current, previous) { |
| 1699 return arraySplice.calculateSplices(current, previous); | 1701 return arraySplice.calculateSplices(current, previous); |
| 1700 }; | 1702 }; |
| 1701 | 1703 |
| 1702 global.ArraySplice = ArraySplice; | 1704 expose.ArraySplice = ArraySplice; |
| 1703 global.ObjectObserver = ObjectObserver; | 1705 expose.ObjectObserver = ObjectObserver; |
| 1704 global.PathObserver = PathObserver; | 1706 expose.PathObserver = PathObserver; |
| 1705 global.CompoundObserver = CompoundObserver; | 1707 expose.CompoundObserver = CompoundObserver; |
| 1706 global.Path = Path; | 1708 expose.Path = Path; |
| 1707 global.ObserverTransform = ObserverTransform; | 1709 expose.ObserverTransform = ObserverTransform; |
| 1710 |
| 1708 })(typeof global !== 'undefined' && global && typeof module !== 'undefined' && m
odule ? global : this || window); | 1711 })(typeof global !== 'undefined' && global && typeof module !== 'undefined' && m
odule ? global : this || window); |
| OLD | NEW |