| 4 | import { capitalize } from "./string_helpers" |
| 5 | |
| 6 | export class ValueObserver implements StringMapObserverDelegate { |
| 7 | readonly context: Context |
| 8 | readonly receiver: any |
| 9 | private stringMapObserver: StringMapObserver |
| 10 | private valueDescriptorMap: { [attributeName: string]: ValueDescriptor } |
| 11 | |
| 12 | constructor(context: Context, receiver: any) { |
| 13 | this.context = context |
| 14 | this.receiver = receiver |
| 15 | this.stringMapObserver = new StringMapObserver(this.element, this) |
| 16 | this.valueDescriptorMap = (this.controller as any).valueDescriptorMap |
| 17 | } |
| 18 | |
| 19 | start() { |
| 20 | this.stringMapObserver.start() |
| 21 | this.invokeChangedCallbacksForDefaultValues() |
| 22 | } |
| 23 | |
| 24 | stop() { |
| 25 | this.stringMapObserver.stop() |
| 26 | } |
| 27 | |
| 28 | get element() { |
| 29 | return this.context.element |
| 30 | } |
| 31 | |
| 32 | get controller() { |
| 33 | return this.context.controller |
| 34 | } |
| 35 | |
| 36 | // String map observer delegate |
| 37 | |
| 38 | getStringMapKeyForAttribute(attributeName: string) { |
| 39 | if (attributeName in this.valueDescriptorMap) { |
| 40 | return this.valueDescriptorMap[attributeName].name |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | stringMapKeyAdded(key: string, attributeName: string) { |
| 45 | const descriptor = this.valueDescriptorMap[attributeName] |
| 46 | |
| 47 | if (!this.hasValue(key)) { |
| 48 | this.invokeChangedCallback(key, descriptor.writer(this.receiver[key]), descriptor.writer(descriptor.defaultValue)) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | stringMapValueChanged(value: string, name: string, oldValue: string) { |
| 53 | const descriptor = this.valueDescriptorNameMap[name] |
| 54 | |
| 55 | if (value === null) return |
| 56 | |
| 57 | if (oldValue === null) { |
| 58 | oldValue = descriptor.writer(descriptor.defaultValue) |
| 59 | } |
| 60 | |
| 61 | this.invokeChangedCallback(name, value, oldValue) |
| 62 | } |
| 63 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…