@kaspernj/api-maker 1.0.137 → 1.0.140

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.137",
19
+ "version": "1.0.140",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
@@ -34,6 +34,24 @@
34
34
  "eslint-find-rules": "eslint-find-rules",
35
35
  "test": "jest"
36
36
  },
37
+ "dependencies": {
38
+ "@rails/actioncable": ">= 6.1.0",
39
+ "clone-deep": ">= 4.0.1",
40
+ "debounce": ">= 1.2.1",
41
+ "diggerize": ">= 1.0.4",
42
+ "epic-locks": ">= 1.0.1",
43
+ "form-data-objectizer": ">= 1.0.0",
44
+ "form-serialize": ">= 0.7.2",
45
+ "format-number": ">= 3.0.0",
46
+ "inflection": ">= 1.12.0",
47
+ "js-money": ">= 0.6.3",
48
+ "numberable": ">= 1.0.0",
49
+ "object-to-formdata": ">= 4.1.0",
50
+ "qs": ">= 6.9.3",
51
+ "replaceall": ">= 0.1.6",
52
+ "strftime": ">= 0.10.0",
53
+ "wake-event": ">= 0.0.1"
54
+ },
37
55
  "peerDependencies": {
38
56
  "prop-types": "^15.7.2",
39
57
  "prop-types-exact": ">= 1.2.0",
@@ -55,23 +73,5 @@
55
73
  "i18n-on-steroids": "^1.0.2",
56
74
  "jest": "^27.0.6",
57
75
  "jsdom": "^19.0.0"
58
- },
59
- "dependencies": {
60
- "@rails/actioncable": ">= 6.1.0",
61
- "clone-deep": ">= 4.0.1",
62
- "debounce": ">= 1.2.1",
63
- "diggerize": ">= 1.0.4",
64
- "epic-locks": ">= 1.0.1",
65
- "form-data-objectizer": ">= 1.0.0",
66
- "form-serialize": ">= 0.7.2",
67
- "format-number": ">= 3.0.0",
68
- "inflection": ">= 1.12.0",
69
- "js-money": ">= 0.6.3",
70
- "numberable": ">= 1.0.0",
71
- "object-to-formdata": ">= 4.1.0",
72
- "qs": ">= 6.9.3",
73
- "replaceall": ">= 0.1.6",
74
- "strftime": ">= 0.10.0",
75
- "wake-event": ">= 0.0.1"
76
76
  }
77
77
  }
package/src/config.js ADDED
@@ -0,0 +1,15 @@
1
+ class ApiMakerConfig {
2
+ getCurrenciesCollection() {
3
+ if (!this._currenciesCollection) throw new Error("Currencies collection hasn't been set")
4
+
5
+ return this._currenciesCollection
6
+ }
7
+
8
+ setCurrenciesCollection(newCurrenciesCollection) {
9
+ this._currenciesCollection = newCurrenciesCollection
10
+ }
11
+ }
12
+
13
+ const apiMakerConfig = new ApiMakerConfig()
14
+
15
+ export default apiMakerConfig
@@ -20,11 +20,6 @@ export default class ApiMakerEventUpdated extends React.PureComponent {
20
20
  onUpdated: PropTypes.func.isRequired
21
21
  })
22
22
 
23
- constructor (props) {
24
- super(props)
25
- this.onConnected = this.onConnected.bind(this)
26
- }
27
-
28
23
  componentDidMount () {
29
24
  this.connect()
30
25
  }
@@ -35,17 +30,17 @@ export default class ApiMakerEventUpdated extends React.PureComponent {
35
30
  }
36
31
 
37
32
  if (this.onConnectedListener) {
38
- this.connectUpdated.events.removeListener("connected", this.onConnected)
33
+ this.connectUpdated.events.removeListener("connected", this.props.onConnected)
39
34
  }
40
35
  }
41
36
 
42
37
  connect () {
43
38
  const {model, onConnected} = this.props
44
39
 
45
- this.connectUpdated = ModelEvents.connectUpdated(model, (...args) => this.onUpdated(...args))
40
+ this.connectUpdated = ModelEvents.connectUpdated(model, this.onUpdated)
46
41
 
47
42
  if (onConnected) {
48
- this.connectUpdated.events.addListener("connected", this.onConnected)
43
+ this.onConnectedListener = this.connectUpdated.events.addListener("connected", this.props.onConnected)
49
44
  }
50
45
  }
51
46
 
@@ -61,11 +56,7 @@ export default class ApiMakerEventUpdated extends React.PureComponent {
61
56
  return this.debounceInstance
62
57
  }
63
58
 
64
- onConnected () {
65
- this.props.onConnected()
66
- }
67
-
68
- onUpdated (...args) {
59
+ onUpdated = (...args) => {
69
60
  if (!this.props.active) {
70
61
  return
71
62
  }
@@ -63,5 +63,5 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
63
63
  )
64
64
  }
65
65
 
66
- onUpdated = ({model}) => this.setState({model})
66
+ onUpdated = () => this.loadExistingModel()
67
67
  }
@@ -54,6 +54,15 @@ module.exports = class MoneyFormatter {
54
54
  return moneyCurrency
55
55
  }
56
56
 
57
+ static isMoney(value) {
58
+ if (value instanceof Money) return true
59
+
60
+ if (typeof value == "object" && value && Object.keys(value).length == 2 && value.amount && value.currency)
61
+ return true
62
+
63
+ return false
64
+ }
65
+
57
66
  constructor (money, args = {}) {
58
67
  this.args = args
59
68
  this.money = money
package/src/routes.cjs CHANGED
@@ -3,6 +3,8 @@ const inflection = require("inflection")
3
3
 
4
4
  module.exports = class ApiMakerRoutes {
5
5
  constructor ({jsRoutes, locale, routeDefinitions}) {
6
+ if (!jsRoutes) throw new Error("'jsRoutes' wasn't given")
7
+
6
8
  this.jsRoutes = jsRoutes
7
9
  this.routeDefinitions = routeDefinitions
8
10