| 4 | @connectable() |
| 5 | @subscriberCollection() |
| 6 | export class ExpressionObserver { |
| 7 | constructor(scope, expression, observerLocator, lookupFunctions) { |
| 8 | this.scope = scope; |
| 9 | this.expression = expression; |
| 10 | this.observerLocator = observerLocator; |
| 11 | this.lookupFunctions = lookupFunctions; |
| 12 | } |
| 13 | |
| 14 | getValue() { |
| 15 | return this.expression.evaluate(this.scope, this.lookupFunctions); |
| 16 | } |
| 17 | |
| 18 | setValue(newValue) { |
| 19 | this.expression.assign(this.scope, newValue); |
| 20 | } |
| 21 | |
| 22 | subscribe(context, callable) { |
| 23 | if (!this.hasSubscribers()) { |
| 24 | this.oldValue = this.expression.evaluate(this.scope, this.lookupFunctions); |
| 25 | this.expression.connect(this, this.scope); |
| 26 | } |
| 27 | this.addSubscriber(context, callable); |
| 28 | if (arguments.length === 1 && context instanceof Function) { |
| 29 | return { |
| 30 | dispose: () => { |
| 31 | this.unsubscribe(context, callable); |
| 32 | } |
| 33 | }; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | unsubscribe(context, callable) { |
| 38 | if (this.removeSubscriber(context, callable) && !this.hasSubscribers()) { |
| 39 | this.unobserve(true); |
| 40 | this.oldValue = undefined; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | call() { |
| 45 | let newValue = this.expression.evaluate(this.scope, this.lookupFunctions); |
| 46 | let oldValue = this.oldValue; |
| 47 | if (newValue !== oldValue) { |
| 48 | this.oldValue = newValue; |
| 49 | this.callSubscribers(newValue, oldValue); |
| 50 | } |
| 51 | this._version++; |
| 52 | this.expression.connect(this, this.scope); |
| 53 | this.unobserve(false); |
| 54 | } |
| 55 | } |
nothing calls this directly
no outgoing calls
no test coverage detected