(models: any[], state: any)
| 208 | |
| 209 | function merge(models: T[], state: R): void; |
| 210 | function merge(models: any[], state: any): void { |
| 211 | models.sort(sort); |
| 212 | |
| 213 | const ids: any[] = []; |
| 214 | |
| 215 | let i = 0; |
| 216 | let j = 0; |
| 217 | |
| 218 | while (i < models.length && j < state.ids.length) { |
| 219 | const model = models[i]; |
| 220 | const modelId = selectIdValue(model, selectId); |
| 221 | const entityId = state.ids[j]; |
| 222 | const entity = state.entities[entityId]; |
| 223 | |
| 224 | if (sort(model, entity) <= 0) { |
| 225 | ids.push(modelId); |
| 226 | i++; |
| 227 | } else { |
| 228 | ids.push(entityId); |
| 229 | j++; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | if (i < models.length) { |
| 234 | state.ids = ids.concat(models.slice(i).map(selectId)); |
| 235 | } else { |
| 236 | state.ids = ids.concat(state.ids.slice(j)); |
| 237 | } |
| 238 | |
| 239 | models.forEach((model, i) => { |
| 240 | state.entities[selectId(model)] = model; |
| 241 | }); |
| 242 | } |
| 243 | |
| 244 | return { |
| 245 | removeOne, |
no test coverage detected