* Update map based styling. * * Map based styling could be anything which contains more than one binding. For example `string`, * or object literal. Dealing with all of these types would complicate the logic so * instead this function expects that the complex input is first converted into normal
( tView: TView, tNode: TNode, lView: LView, renderer: Renderer, oldKeyValueArray: KeyValueArray<any>, newKeyValueArray: KeyValueArray<any>, isClassBased: boolean, bindingIndex: number, )
| 806 | * @param bindingIndex Binding index of the binding. |
| 807 | */ |
| 808 | function updateStylingMap( |
| 809 | tView: TView, |
| 810 | tNode: TNode, |
| 811 | lView: LView, |
| 812 | renderer: Renderer, |
| 813 | oldKeyValueArray: KeyValueArray<any>, |
| 814 | newKeyValueArray: KeyValueArray<any>, |
| 815 | isClassBased: boolean, |
| 816 | bindingIndex: number, |
| 817 | ) { |
| 818 | if ((oldKeyValueArray as KeyValueArray<any> | NO_CHANGE) === NO_CHANGE) { |
| 819 | // On first execution the oldKeyValueArray is NO_CHANGE => treat it as empty KeyValueArray. |
| 820 | oldKeyValueArray = EMPTY_ARRAY as any; |
| 821 | } |
| 822 | let oldIndex = 0; |
| 823 | let newIndex = 0; |
| 824 | let oldKey: string | null = 0 < oldKeyValueArray.length ? oldKeyValueArray[0] : null; |
| 825 | let newKey: string | null = 0 < newKeyValueArray.length ? newKeyValueArray[0] : null; |
| 826 | while (oldKey !== null || newKey !== null) { |
| 827 | ngDevMode && assertLessThan(oldIndex, 999, 'Are we stuck in infinite loop?'); |
| 828 | ngDevMode && assertLessThan(newIndex, 999, 'Are we stuck in infinite loop?'); |
| 829 | const oldValue = |
| 830 | oldIndex < oldKeyValueArray.length ? oldKeyValueArray[oldIndex + 1] : undefined; |
| 831 | const newValue = |
| 832 | newIndex < newKeyValueArray.length ? newKeyValueArray[newIndex + 1] : undefined; |
| 833 | let setKey: string | null = null; |
| 834 | let setValue: any = undefined; |
| 835 | if (oldKey === newKey) { |
| 836 | // UPDATE: Keys are equal => new value is overwriting old value. |
| 837 | oldIndex += 2; |
| 838 | newIndex += 2; |
| 839 | if (oldValue !== newValue) { |
| 840 | setKey = newKey; |
| 841 | setValue = newValue; |
| 842 | } |
| 843 | } else if (newKey === null || (oldKey !== null && oldKey < newKey!)) { |
| 844 | // DELETE: oldKey key is missing or we did not find the oldKey in the newValue |
| 845 | // (because the keyValueArray is sorted and `newKey` is found later alphabetically). |
| 846 | // `"background" < "color"` so we need to delete `"background"` because it is not found in the |
| 847 | // new array. |
| 848 | oldIndex += 2; |
| 849 | setKey = oldKey; |
| 850 | } else { |
| 851 | // CREATE: newKey's is earlier alphabetically than oldKey's (or no oldKey) => we have new key. |
| 852 | // `"color" > "background"` so we need to add `color` because it is in new array but not in |
| 853 | // old array. |
| 854 | ngDevMode && assertDefined(newKey, 'Expecting to have a valid key'); |
| 855 | newIndex += 2; |
| 856 | setKey = newKey; |
| 857 | setValue = newValue; |
| 858 | } |
| 859 | if (setKey !== null) { |
| 860 | updateStyling(tView, tNode, lView, renderer, setKey, setValue, isClassBased, bindingIndex); |
| 861 | } |
| 862 | oldKey = oldIndex < oldKeyValueArray.length ? oldKeyValueArray[oldIndex] : null; |
| 863 | newKey = newIndex < newKeyValueArray.length ? newKeyValueArray[newIndex] : null; |
| 864 | } |
| 865 | } |
no test coverage detected