@kaspernj/api-maker 1.0.284 → 1.0.285
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
package/src/base-model.mjs
CHANGED
|
@@ -222,7 +222,17 @@ export default class BaseModel {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
attributes () {
|
|
225
|
-
|
|
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.
|
|
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
|
-
|
|
49
|
-
|
|
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
|
-
|
|
66
|
+
return md5.end()
|
|
67
|
+
}
|
|
58
68
|
|
|
59
|
-
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
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
|
|