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

ecamp / hal-json-vuex / 13321877237

13 Feb 2025 10:43PM UTC coverage: 84.708%. Remained the same
13321877237

push

github

web-flow
Update babel monorepo to v7.26.8

159 of 206 branches covered (77.18%)

Branch coverage included in aggregate %.

262 of 291 relevant lines covered (90.03%)

740.07 hits per line

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

83.33
/src/StoreValueCreator.js
1
import StoreValue from './StoreValue.js'
2
import LoadingStoreValue from './LoadingStoreValue.js'
3

4
class StoreValueCreator {
5
  constructor ({ get, reload, post, patch, del, isUnknown }, config = {}) {
×
6
    this.apiActions = { get, reload, post, patch, del, isUnknown }
333✔
7
    this.config = config
333✔
8
  }
9

10
  /**
11
   * Takes data from the Vuex store and makes it more usable in frontend components. The data stored
12
   * in the Vuex store should always be JSON serializable according to
13
   * https://github.com/vuejs/vuex/issues/757#issuecomment-297668640. Therefore, we wrap the data into
14
   * a new object, and provide accessor methods for related entities. Such an accessor method fetches the
15
   * related entity from the Vuex store (or the API if necessary) when called. In case the related entity
16
   * is still being loaded from the API, a LoadingStoreValue is returned.
17
   *
18
   * Example:
19
   * // Data of an entity like it comes from the Vuex store:
20
   * let storeData = {
21
   *   numeric_property: 3,
22
   *   reference_to_other_entity: {
23
   *     href: '/uri/of/other/entity'
24
   *   },
25
   *   _meta: {
26
   *     self: '/self/uri'
27
   *   }
28
   * }
29
   * // Apply StoreValue
30
   * let usable = storeValue(...)(storeData)
31
   * // Now we can use accessor methods
32
   * usable.reference_to_other_entity() // returns the result of this.api.get('/uri/of/other/entity')
33
   *
34
   * @param data                entity data from the Vuex store
35
   * @returns object            wrapped entity ready for use in a frontend component
36
   */
37
  wrap (data) {
38
    const meta = data._meta || { load: Promise.resolve() }
1,431!
39

40
    if (meta.loading) {
1,431✔
41
      const entityLoaded = meta.load.then(loadedData => new StoreValue(loadedData, this.apiActions, this, this.config))
384✔
42
      return new LoadingStoreValue(entityLoaded, this.config.apiRoot + meta.self)
384✔
43
    }
44

45
    return new StoreValue(data, this.apiActions, this, this.config)
1,047✔
46
  }
47
}
48

49
export default StoreValueCreator
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