(element: any)
| 151 | } |
| 152 | |
| 153 | @action put(element: any) { |
| 154 | const id = element[this.descriptor.fieldId]; |
| 155 | if (!this.resolved) { |
| 156 | this.idsBeforeResolve.add(String(id)); |
| 157 | } |
| 158 | |
| 159 | const old = this.byId.get(String(id)); |
| 160 | if (old !== undefined) { |
| 161 | if (!this.queryExecutor.isAllowedByFilters(element)) { |
| 162 | // existing item, but updated data has property that filters out the element outright |
| 163 | if (this.queryExecutor.limit !== null && |
| 164 | this.array.length === this.queryExecutor.limit && |
| 165 | this.byId.size > this.array.length) |
| 166 | { |
| 167 | // Array was limited, however there are more up-to-date data in byId that can be filled |
| 168 | // in. |
| 169 | this.byId.delete(String(id)); |
| 170 | this.array.replace([...this.byId.values()]); |
| 171 | this.recomputeQuery(); |
| 172 | } else { |
| 173 | this.byId.delete(String(id)); |
| 174 | this.deleteFromArray(old); |
| 175 | } |
| 176 | return; |
| 177 | } |
| 178 | // update items that are not filtered out |
| 179 | old.update(element); |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | if (!this.queryExecutor.isAllowedByFilters(element)) { |
| 184 | // ignore items that are filtered out |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | // add items that are not filtered out |
| 189 | const instance = this.descriptor.parse(this.accessor, element); |
| 190 | this.byId.set(instance.id, instance); |
| 191 | this.array.push(instance); |
| 192 | } |
| 193 | |
| 194 | @action clear() { |
| 195 | this.array.replace([]); |
no test coverage detected