inertia-sails 0.0.5 → 0.0.8
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/index.js +28 -17
- package/package.json +1 -1
- package/private/get-page-props.js +4 -1
package/index.js
CHANGED
|
@@ -19,13 +19,33 @@ module.exports = function defineInertiaHook(sails) {
|
|
|
19
19
|
let sharedProps = {}
|
|
20
20
|
let sharedViewData = {}
|
|
21
21
|
let rootView = 'app'
|
|
22
|
-
let version
|
|
23
22
|
return {
|
|
23
|
+
defaults: {
|
|
24
|
+
inertia: {
|
|
25
|
+
version: 1,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
initialize: async function (cb) {
|
|
29
|
+
hook = this
|
|
30
|
+
sails.inertia = hook
|
|
31
|
+
|
|
32
|
+
hook.share('flash', {
|
|
33
|
+
success: null,
|
|
34
|
+
error: null,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
hook.share('errors', {})
|
|
38
|
+
|
|
39
|
+
return cb()
|
|
40
|
+
},
|
|
41
|
+
|
|
24
42
|
share: (key, value = null) => (sharedProps[key] = value),
|
|
25
43
|
|
|
26
44
|
getShared: (key = null) => sharedProps[key] ?? sharedProps,
|
|
27
45
|
|
|
28
|
-
flushShared: () =>
|
|
46
|
+
flushShared: (key) => {
|
|
47
|
+
key ? delete sharedProps[key] : (sharedProps = {})
|
|
48
|
+
},
|
|
29
49
|
|
|
30
50
|
viewData: (key, value) => (sharedViewData[key] = value),
|
|
31
51
|
|
|
@@ -35,25 +55,12 @@ module.exports = function defineInertiaHook(sails) {
|
|
|
35
55
|
|
|
36
56
|
getRootView: () => rootView,
|
|
37
57
|
|
|
38
|
-
version: (newVersion) => (version = newVersion),
|
|
39
|
-
|
|
40
|
-
getVersion: () => version,
|
|
41
|
-
|
|
42
|
-
initialize: async function (cb) {
|
|
43
|
-
hook = this
|
|
44
|
-
return cb()
|
|
45
|
-
},
|
|
46
|
-
|
|
47
58
|
routes: {
|
|
48
59
|
before: {
|
|
49
60
|
'GET /*': {
|
|
50
61
|
skipAssets: true,
|
|
51
62
|
fn: function (req, res, next) {
|
|
52
|
-
hook.render =
|
|
53
|
-
component,
|
|
54
|
-
props = {},
|
|
55
|
-
viewData = {}
|
|
56
|
-
) {
|
|
63
|
+
hook.render = function (component, props = {}, viewData = {}) {
|
|
57
64
|
const allProps = {
|
|
58
65
|
...sharedProps,
|
|
59
66
|
...props,
|
|
@@ -65,7 +72,11 @@ module.exports = function defineInertiaHook(sails) {
|
|
|
65
72
|
}
|
|
66
73
|
|
|
67
74
|
let url = req.url || req.originalUrl
|
|
68
|
-
const
|
|
75
|
+
const assetVersion = sails.config.inertia.version
|
|
76
|
+
const currentVersion =
|
|
77
|
+
typeof assetVersion == 'function'
|
|
78
|
+
? assetVersion()
|
|
79
|
+
: assetVersion
|
|
69
80
|
|
|
70
81
|
const page = {
|
|
71
82
|
component,
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
// Implement lazy data evaluation
|
|
2
|
+
// Userland can pass functions that returns a value becuase of this algorithm
|
|
3
|
+
// However do note to make all async operations outside the render() method in userland
|
|
2
4
|
module.exports = function (allProps, dataKeys = []) {
|
|
3
5
|
let props = {}
|
|
4
6
|
for (const key of dataKeys) {
|
|
5
|
-
if (typeof
|
|
7
|
+
if (typeof allProps[key] === 'function') {
|
|
6
8
|
props[key] = allProps[key]()
|
|
7
9
|
} else {
|
|
8
10
|
props[key] = allProps[key]
|
|
9
11
|
}
|
|
10
12
|
}
|
|
13
|
+
|
|
11
14
|
return props
|
|
12
15
|
}
|