@kaspernj/api-maker 1.0.195 → 1.0.198

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.195",
19
+ "version": "1.0.198",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
package/src/config.js CHANGED
@@ -1,50 +1,48 @@
1
+ import inflection from "inflection"
2
+
3
+ const accessors = {
4
+ breakPoints: {
5
+ default: [
6
+ ["xxl", 1400],
7
+ ["xl", 1200],
8
+ ["lg", 992],
9
+ ["md", 768],
10
+ ["sm", 576],
11
+ ["xs", 0]
12
+ ],
13
+ required: true
14
+ },
15
+ currenciesCollection: {required: true},
16
+ history: {required: false},
17
+ host: {required: false},
18
+ routes: {required: false},
19
+ routeDefinitions: {required: false}
20
+ }
21
+
1
22
  class ApiMakerConfig {
2
23
  constructor() {
3
24
  if (!global.apiMakerConfigGlobal) global.apiMakerConfigGlobal = {}
4
25
 
5
26
  this.global = global.apiMakerConfigGlobal
6
27
  }
28
+ }
7
29
 
8
- getCurrenciesCollection() {
9
- if (!this.global.currenciesCollection) throw new Error("Currencies collection hasn't been set")
10
-
11
- return this.global.currenciesCollection
12
- }
13
-
14
- getHost() {
15
- const host = this.global.host
16
-
17
- if (typeof host == "function") return host()
18
-
19
- return host
20
- }
21
-
22
- getRouteDefinitions() {
23
- return this.global.routeDefinitions
24
- }
30
+ for (const accessorName in accessors) {
31
+ const accessorData = accessors[accessorName]
32
+ const camelizedAccessor = inflection.camelize(accessorName)
25
33
 
26
- getRoutes() {
27
- return this.global.routes
28
- }
34
+ ApiMakerConfig.prototype[`set${camelizedAccessor}`] = function (newValue) { this.global[accessorName] = newValue }
35
+ ApiMakerConfig.prototype[`get${camelizedAccessor}`] = function (...args) {
36
+ if (!this.global[accessorName]) {
37
+ if (accessorData.default) return accessorData.default
38
+ if (accessorData.required) throw new Error(`${accessorName} hasn't been set`)
39
+ }
29
40
 
30
- setCurrenciesCollection(newCurrenciesCollection) {
31
- this.global.currenciesCollection = newCurrenciesCollection
32
- }
41
+ const value = this.global[accessorName]
33
42
 
34
- setHistory(history) {
35
- this.global.history = history
36
- }
37
-
38
- setHost(host) {
39
- this.global.host = host
40
- }
41
-
42
- setRouteDefinitions(routeDefinitions) {
43
- this.global.routeDefinitions = routeDefinitions
44
- }
43
+ if (typeof value == "function") return value(...args)
45
44
 
46
- setRoutes(routes) {
47
- this.global.routes = routes
45
+ return value
48
46
  }
49
47
  }
50
48
 
@@ -12,10 +12,14 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
12
12
  }
13
13
 
14
14
  componentDidMount() {
15
+ this.loadModel()
16
+ }
17
+
18
+ loadModel = async () => {
15
19
  if (args.newIfNoId && !this.getModelId()) {
16
- this.loadNewModel()
20
+ return await this.loadNewModel()
17
21
  } else if (!args.optional || this.getModelId()) {
18
- this.loadExistingModel()
22
+ return await this.loadExistingModel()
19
23
  }
20
24
  }
21
25
 
@@ -23,7 +27,7 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
23
27
  return this.props.match.params[this.paramsVariableName] || this.props.match.params.id
24
28
  }
25
29
 
26
- async loadExistingModel() {
30
+ loadExistingModel = async () => {
27
31
  const {modelId} = digs(this.state, "modelId")
28
32
  const query = await ModelClass.ransack({id_eq: modelId})
29
33
 
@@ -57,6 +61,7 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
57
61
  }
58
62
 
59
63
  render() {
64
+ const {onUpdated, reloadModel} = digs(this, "onUpdated", "reloadModel")
60
65
  const {model, modelId} = digs(this.state, "model", "modelId")
61
66
  const wrappedComponentProps = {}
62
67
 
@@ -65,13 +70,17 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
65
70
 
66
71
  return (
67
72
  <>
73
+ {args.events &&
74
+ <EventEmitterListener event="reloadModel" events={args.events} onCalled={reloadModel} />
75
+ }
68
76
  {model && args.eventUpdated &&
69
- <EventUpdated model={model} onUpdated={digg(this, "onUpdated")} />
77
+ <EventUpdated model={model} onUpdated={onUpdated} />
70
78
  }
71
79
  <WrappedComponent {...wrappedComponentProps} {...this.props} />
72
80
  </>
73
81
  )
74
82
  }
75
83
 
76
- onUpdated = () => this.loadExistingModel()
84
+ reloadModel = () => this.loadModel()
85
+ onUpdated = this.loadExistingModel
77
86
  }
@@ -99,7 +99,7 @@ module.exports = class SourceMapsLoader {
99
99
  }
100
100
 
101
101
  includeMapURL(src) {
102
- return src.includes("/packs/") || src.includes("/assets/")
102
+ return src.includes("/packs/")
103
103
  }
104
104
 
105
105
  async loadSourceMapForSource ({originalUrl, sourceMapUrl}) {