@kaspernj/api-maker 1.0.284 → 1.0.286

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.284",
19
+ "version": "1.0.286",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -74,7 +74,7 @@
74
74
  "eslint-find-rules": "^4.0.0",
75
75
  "eslint-plugin-jest": "^27.0.1",
76
76
  "eslint-plugin-react": "^7.23.2",
77
- "i18n-on-steroids": "^1.0.5",
77
+ "i18n-on-steroids": "^1.0.7",
78
78
  "jest": "^29.0.1",
79
79
  "jsdom": "^22.0.0"
80
80
  }
@@ -222,7 +222,17 @@ export default class BaseModel {
222
222
  }
223
223
 
224
224
  attributes () {
225
- return digg(this, "modelData")
225
+ const result = {}
226
+
227
+ for (const key in this.modelData) {
228
+ result[key] = this.modelData[key]
229
+ }
230
+
231
+ for (const key in this.changes) {
232
+ result[key] = this.changes[key]
233
+ }
234
+
235
+ return result
226
236
  }
227
237
 
228
238
  can (givenAbilityName) {
@@ -271,6 +281,12 @@ export default class BaseModel {
271
281
  }
272
282
  }
273
283
 
284
+ localCacheKey() {
285
+ const cacheKeyGenerator = new CacheKeyGenerator(this)
286
+
287
+ return cacheKeyGenerator.local()
288
+ }
289
+
274
290
  fullCacheKey() {
275
291
  const cacheKeyGenerator = new CacheKeyGenerator(this)
276
292
 
@@ -2,11 +2,20 @@ import SparkMD5 from "spark-md5"
2
2
 
3
3
  export default class CacheKeyGenerator {
4
4
  constructor(model) {
5
+ this.model = model
5
6
  this.allModels = [model]
6
7
  this.readModels = {}
7
8
  this.recordModelType(model.modelClassData().name)
8
9
  this.recordModel(model.modelClassData().name, model)
9
- this.fillModels(model)
10
+ this.filledModels = false
11
+ }
12
+
13
+ local() {
14
+ const md5 = new SparkMD5()
15
+
16
+ this.feedModel(this.model, md5)
17
+
18
+ return md5.end()
10
19
  }
11
20
 
12
21
  recordModelType(relationshipType) {
@@ -39,32 +48,42 @@ export default class CacheKeyGenerator {
39
48
  this.fillModels(anotherModel)
40
49
  }
41
50
  }
51
+
52
+ this.filledModels = true
42
53
  }
43
54
 
44
55
  cacheKey() {
56
+ if (!this.filledModels) {
57
+ this.fillModels(this.model)
58
+ }
59
+
45
60
  const md5 = new SparkMD5()
46
61
 
47
62
  for (const model of this.allModels) {
48
- md5.append("--model--")
49
- md5.append(model.modelClassData().name)
50
- md5.append("--unique-key--")
51
- md5.append(model.id() || model.uniqueKey())
52
-
53
- if (model.markedForDestruction()) {
54
- md5.append("--marked-for-destruction--")
55
- }
63
+ this.feedModel(model, md5)
64
+ }
56
65
 
57
- md5.append("-attributes-")
66
+ return md5.end()
67
+ }
58
68
 
59
- const attributes = model.attributes()
69
+ feedModel(model, md5) {
70
+ md5.append("--model--")
71
+ md5.append(model.modelClassData().name)
72
+ md5.append("--unique-key--")
73
+ md5.append(model.id() || model.uniqueKey())
60
74
 
61
- for (const attributeName in attributes) {
62
- md5.append(attributeName)
63
- md5.append("--attribute--")
64
- md5.append(`${model.readAttributeUnderscore(attributeName)}`)
65
- }
75
+ if (model.markedForDestruction()) {
76
+ md5.append("--marked-for-destruction--")
66
77
  }
67
78
 
68
- return md5.end()
79
+ md5.append("-attributes-")
80
+
81
+ const attributes = model.attributes()
82
+
83
+ for (const attributeName in attributes) {
84
+ md5.append(attributeName)
85
+ md5.append("--attribute--")
86
+ md5.append(`${model.readAttributeUnderscore(attributeName)}`)
87
+ }
69
88
  }
70
89
  }
@@ -9,11 +9,6 @@ export default class ApiMakerEventEmitterListener extends React.PureComponent {
9
9
  onCalled: PropTypes.func.isRequired
10
10
  }
11
11
 
12
- constructor (props) {
13
- super(props)
14
- this.onCalled = this.onCalled.bind(this)
15
- }
16
-
17
12
  componentDidMount () {
18
13
  this.props.events.addListener(this.props.event, this.onCalled)
19
14
  }
@@ -22,7 +17,7 @@ export default class ApiMakerEventEmitterListener extends React.PureComponent {
22
17
  this.props.events.removeListener(this.props.event, this.onCalled)
23
18
  }
24
19
 
25
- onCalled (...args) {
20
+ onCalled = (...args) => {
26
21
  this.props.onCalled.apply(null, ...args)
27
22
  }
28
23
 
@@ -1,5 +1,6 @@
1
1
  import PropTypes from "prop-types"
2
2
  import PropTypesExact from "prop-types-exact"
3
+ import React from "react"
3
4
 
4
5
  export default class ApiMakerResizeObserver extends React.PureComponent {
5
6
  static propTypes = PropTypesExact({
@@ -33,8 +33,10 @@ export default class ApiMakerRoutesNative {
33
33
 
34
34
  if (variableMatch) {
35
35
  localizedPathParts.push({type: "variable", count: variableCount++})
36
- } else {
37
- localizedPathParts.push({type: "pathPart", name: dig(this.routeTranslationParts, locale, pathPart) || pathPart})
36
+ } else if (pathPart) {
37
+ const name = this.i18n.t(`routes.${pathPart}`, null, {default: pathPart, locale})
38
+
39
+ localizedPathParts.push({type: "pathPart", name})
38
40
  }
39
41
  }
40
42
 
@@ -63,6 +65,7 @@ export default class ApiMakerRoutesNative {
63
65
  }
64
66
 
65
67
  loadRouteTranslations (i18n) {
68
+ this.i18n = i18n
66
69
  const locales = digg(i18n, "locales")
67
70
 
68
71
  for (const locale in locales) {