MCPcopy Create free account
hub / github.com/aurelia/binding / synchronizeValue

Method synchronizeValue

src/select-value-observer.js:74–127  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

72 }
73
74 synchronizeValue() {
75 let options = this.element.options;
76 let count = 0;
77 let value = [];
78
79 for (let i = 0, ii = options.length; i < ii; i++) {
80 let option = options.item(i);
81 if (!option.selected) {
82 continue;
83 }
84 value.push(option.hasOwnProperty('model') ? option.model : option.value);
85 count++;
86 }
87
88 if (this.element.multiple) {
89 // multi-select
90 if (Array.isArray(this.value)) {
91 let matcher = this.element.matcher || ((a, b) => a === b);
92 // remove items that are no longer selected.
93 let i = 0;
94 while (i < this.value.length) {
95 let a = this.value[i];
96 if (value.findIndex(b => matcher(a, b)) === -1) { // eslint-disable-line no-loop-func
97 this.value.splice(i, 1);
98 } else {
99 i++;
100 }
101 }
102 // add items that have been selected.
103 i = 0;
104 while (i < value.length) {
105 let a = value[i];
106 if (this.value.findIndex(b => matcher(a, b)) === -1) { // eslint-disable-line no-loop-func
107 this.value.push(a);
108 }
109 i++;
110 }
111 return; // don't notify.
112 }
113 } else {
114 // single-select
115 if (count === 0) {
116 value = null;
117 } else {
118 value = value[0];
119 }
120 }
121
122 if (value !== this.value) {
123 this.oldValue = this.value;
124 this.value = value;
125 this.notify();
126 }
127 }
128
129 notify() {
130 let oldValue = this.oldValue;

Callers 2

handleEventMethod · 0.95
bindMethod · 0.95

Calls 2

notifyMethod · 0.95
matcherFunction · 0.85

Tested by

no test coverage detected