• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ecamp / hal-json-vuex / 5566299053

pending completion
5566299053

push

github

web-flow
Merge pull request #285 from usu/chore/node-20

chore: add support for node 20

139 of 164 branches covered (84.76%)

Branch coverage included in aggregate %.

300 of 319 relevant lines covered (94.04%)

1268.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.21
/src/LoadingCollection.ts
1
import LoadingResource from './LoadingResource'
9✔
2
import ResourceInterface from './interfaces/ResourceInterface'
3

4
class LoadingCollection {
5
  /**
6
   * Returns a placeholder for an array that has not yet finished loading from the API. The array placeholder
7
   * will respond to functional calls (like .find(), .map(), etc.) with further LoadingStoreCollections or
8
   * LoadingStoreValues. If passed the existingContent argument, random access and .length will also work.
9
   * @param loadArray       Promise that resolves once the array has finished loading
10
   * @param existingContent optionally set the elements that are already known, for random access
11
   */
12
  static create (loadArray: Promise<Array<ResourceInterface> | undefined>, existingContent: Array<ResourceInterface> = []): Array<ResourceInterface> {
45✔
13
    // if Promsise resolves to undefined, provide empty array
14
    // this could happen if items is accessed from a LoadingResource, which resolves to a normal entity without 'items'
15
    const loadArraySafely = loadArray.then(array => array ?? [])
51!
16

17
    // proxy array function 'find' to a LoadingResource (Resource)
18
    const singleResultFunctions = ['find']
51✔
19
    singleResultFunctions.forEach(func => {
51✔
20
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
      existingContent[func] = (...args: any[]) => {
51✔
22
        const resultLoaded = loadArraySafely.then(array => array[func](...args) as ResourceInterface)
×
23
        return new LoadingResource(resultLoaded)
×
24
      }
25
    })
26

27
    // proxy array functions with multiple results to a LoadingCollection (Array<ResourceInterface>)
28
    const arrayResultFunctions = ['map', 'flatMap', 'filter']
51✔
29
    arrayResultFunctions.forEach(func => {
51✔
30
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
      existingContent[func] = (...args: any[]) => {
153✔
32
        const resultLoaded = loadArraySafely.then(array => array[func](...args) as Array<ResourceInterface>) // TODO: return type for .map() is not necessarily an Array<ResourceInterface>
15✔
33
        return LoadingCollection.create(resultLoaded)
15✔
34
      }
35
    })
36
    return existingContent
51✔
37
  }
38
}
39

40
export default LoadingCollection
9✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc