@lightningjs/blits 0.9.5 → 0.9.7
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/CHANGELOG.md +56 -40
- package/boilerplate/common/eslint/.eslintrc.cjs +1 -1
- package/boilerplate/common/git/gitignore +4 -1
- package/boilerplate/js/default/.env.example +4 -0
- package/boilerplate/js/default/src/pages/Home.js +1 -1
- package/boilerplate/js/default/vite.config.js +2 -0
- package/package.json +2 -2
- package/src/application.d.ts +25 -0
- package/src/component.js +1 -1
- package/src/lib/codegenerator/generator.js +8 -5
- package/src/lib/reactivity/effect.js +1 -0
- package/src/lib/reactivity/reactive.js +10 -1
- package/src/lib/setup/state.js +1 -1
- package/src/router/router.js +22 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## v0.9.7
|
|
4
|
+
|
|
5
|
+
_15 apr 2024_
|
|
6
|
+
|
|
7
|
+
- Added support for direct assignment of an Array element and triggering reactivity
|
|
8
|
+
- Added support for .env in boilerplate
|
|
9
|
+
- Fixed issue with Blits component being wrapped in a Proxy when assigned to a state variable
|
|
10
|
+
- Fixed built-in `hasFocus`-state to also work for components that don't have state in their config object
|
|
11
|
+
|
|
12
|
+
## v0.9.6
|
|
13
|
+
|
|
14
|
+
_4 apr 2024_
|
|
15
|
+
|
|
16
|
+
- Added before hook to router
|
|
17
|
+
- Upgraded Lightning renderer to v0.8.2
|
|
18
|
+
|
|
19
|
+
## v0.9.5
|
|
4
20
|
|
|
5
21
|
_29 mar 2024_
|
|
6
22
|
|
|
7
23
|
- Fixed cancelling of scheduled / running transitions when starting a new transition on the same prop (broke in v0.7.1).
|
|
8
24
|
- Added viewport relates lifecycle hooks
|
|
9
25
|
|
|
10
|
-
|
|
26
|
+
## v0.9.4
|
|
11
27
|
|
|
12
28
|
_28 mar 2024_
|
|
13
29
|
|
|
@@ -16,19 +32,19 @@ _28 mar 2024_
|
|
|
16
32
|
- Introduced new `gpuMemoryLimit` launch setting
|
|
17
33
|
|
|
18
34
|
|
|
19
|
-
|
|
35
|
+
## v0.9.3
|
|
20
36
|
|
|
21
37
|
_25 mar 2024_
|
|
22
38
|
|
|
23
39
|
- Added support for mount / pivot on Text elements and Sprites.
|
|
24
40
|
|
|
25
|
-
|
|
41
|
+
## v0.9.2
|
|
26
42
|
|
|
27
43
|
_21 mar 2024_
|
|
28
44
|
|
|
29
45
|
- Fixed issue with updates not triggering during array operation
|
|
30
46
|
|
|
31
|
-
|
|
47
|
+
## v0.9.1
|
|
32
48
|
|
|
33
49
|
_21 mar 2024_
|
|
34
50
|
|
|
@@ -38,7 +54,7 @@ _21 mar 2024_
|
|
|
38
54
|
- Introduced `viewportMargin` setting
|
|
39
55
|
- Added `undefined`-check for props sent to renderer
|
|
40
56
|
|
|
41
|
-
|
|
57
|
+
## v0.9.0
|
|
42
58
|
|
|
43
59
|
_18 mar 2024_
|
|
44
60
|
|
|
@@ -48,7 +64,7 @@ _18 mar 2024_
|
|
|
48
64
|
- Refactored font loading, removed the need for temporary `src/fontLoader.js` file
|
|
49
65
|
- Replaced using component name with unique identifier for registering and emitting hooks
|
|
50
66
|
|
|
51
|
-
|
|
67
|
+
## v0.8.1
|
|
52
68
|
|
|
53
69
|
_9 mar 2024_
|
|
54
70
|
|
|
@@ -57,20 +73,20 @@ _9 mar 2024_
|
|
|
57
73
|
- Removed explicit destroy of child nodes, as the renderer now takes care of this
|
|
58
74
|
- Re-added support for clipping
|
|
59
75
|
|
|
60
|
-
|
|
76
|
+
## v0.8.0
|
|
61
77
|
|
|
62
78
|
_1 mar 2024_
|
|
63
79
|
|
|
64
80
|
- Added `this.$clearIntervals()` and `this.$clearTimeouts()` methods that clear all intervals and timers set on a certain component
|
|
65
81
|
- **Breaking change:** Renamed the key `function` to `easing` in the transitions object used to specify a custom easing functio (deprecation notice added)
|
|
66
82
|
|
|
67
|
-
|
|
83
|
+
## v0.7.4
|
|
68
84
|
|
|
69
85
|
_28 feb 2024_
|
|
70
86
|
|
|
71
87
|
- Fixed dependency for on the fly MSDF font generation
|
|
72
88
|
|
|
73
|
-
|
|
89
|
+
## v0.7.3
|
|
74
90
|
|
|
75
91
|
_28 feb 2024_
|
|
76
92
|
|
|
@@ -81,14 +97,14 @@ _28 feb 2024_
|
|
|
81
97
|
- Added support for pre-compilation for files with more than 1 Blits component
|
|
82
98
|
- Fixed transitions on scale attribute when passed an object with `x` and `y` values
|
|
83
99
|
|
|
84
|
-
|
|
100
|
+
## v0.7.2
|
|
85
101
|
|
|
86
102
|
_23 feb 2024_
|
|
87
103
|
|
|
88
104
|
- Added small fix to support for (re)assigning an array used in a for-loop
|
|
89
105
|
- Added option to enable the Lightning inspector in launch setting (`inspector: true/false`)
|
|
90
106
|
|
|
91
|
-
|
|
107
|
+
## v0.7.1
|
|
92
108
|
|
|
93
109
|
_22 feb 2024_
|
|
94
110
|
|
|
@@ -101,7 +117,7 @@ _22 feb 2024_
|
|
|
101
117
|
- Added preliminary support for frameTick hook
|
|
102
118
|
- Upgraded to latest version of the renderer (0.7.4)
|
|
103
119
|
|
|
104
|
-
|
|
120
|
+
## v0.7.0
|
|
105
121
|
|
|
106
122
|
_20 feb 2024_
|
|
107
123
|
|
|
@@ -110,7 +126,7 @@ _20 feb 2024_
|
|
|
110
126
|
- Added functionality to pass extra data / props when navigating to a new route ( _breaking change_ in signature of `router.to()` method - previously: `router.to(path, options)`, now: `router.to(path, data, options)`)
|
|
111
127
|
- Added configuration option to set the canvas color (aka clear color)
|
|
112
128
|
|
|
113
|
-
|
|
129
|
+
## v0.6.13
|
|
114
130
|
|
|
115
131
|
_16 feb 2024_
|
|
116
132
|
|
|
@@ -120,7 +136,7 @@ _16 feb 2024_
|
|
|
120
136
|
- Fixed logic to not unfoces a parent when it passes focus to a child
|
|
121
137
|
- Removed temporary fix for renderer issue [#123](https://github.com/lightning-js/renderer/issues/123)
|
|
122
138
|
|
|
123
|
-
|
|
139
|
+
## v0.6.12
|
|
124
140
|
|
|
125
141
|
_9 feb 2024_
|
|
126
142
|
|
|
@@ -128,7 +144,7 @@ _9 feb 2024_
|
|
|
128
144
|
- Fixed issue with `.gitignore` in app create flow
|
|
129
145
|
- Added support for dynamic route parts in the router (i.e `/tv/:series/episodes/:episode`)
|
|
130
146
|
|
|
131
|
-
|
|
147
|
+
## v0.6.11
|
|
132
148
|
|
|
133
149
|
_7 feb 2024_
|
|
134
150
|
|
|
@@ -136,7 +152,7 @@ _7 feb 2024_
|
|
|
136
152
|
- Removed setting focus to AppComponent on back key press in RouterView
|
|
137
153
|
- Fixed broken app create flow caused by missing dev dependencies in npx command (temporary fix)
|
|
138
154
|
|
|
139
|
-
|
|
155
|
+
## v0.6.10
|
|
140
156
|
|
|
141
157
|
_2 feb 2024_
|
|
142
158
|
|
|
@@ -145,20 +161,20 @@ _2 feb 2024_
|
|
|
145
161
|
- Updated flow to create a new App project with an interactive prompt of questions (`npx @lightningjs/blits@latest`)
|
|
146
162
|
- Upgraded to latest version of the Lightning 3 renderer (0.7.1)
|
|
147
163
|
|
|
148
|
-
|
|
164
|
+
## v0.6.9
|
|
149
165
|
|
|
150
166
|
_31 jan 2024_
|
|
151
167
|
|
|
152
168
|
- Fixed single quote escaping for all browsers (removing sometimes unsupported negative lookahead)
|
|
153
169
|
- Fixed issue with focus when navigating back to a page that is kept in history
|
|
154
170
|
|
|
155
|
-
|
|
171
|
+
## v0.6.8
|
|
156
172
|
|
|
157
173
|
_29 jan 2024_
|
|
158
174
|
|
|
159
175
|
- Reverted fix (initially) empty for-loops
|
|
160
176
|
|
|
161
|
-
|
|
177
|
+
## v0.6.7
|
|
162
178
|
|
|
163
179
|
_26 jan 2024_
|
|
164
180
|
|
|
@@ -168,7 +184,7 @@ _26 jan 2024_
|
|
|
168
184
|
- Added setting for specifying maximum number of web workers to spawn (`webWorkersLimit`)
|
|
169
185
|
- Added fix for issue with setting up reactivity for (initially) empty for-loops
|
|
170
186
|
|
|
171
|
-
|
|
187
|
+
## v0.6.6
|
|
172
188
|
|
|
173
189
|
_24 jan 2024_
|
|
174
190
|
|
|
@@ -176,54 +192,54 @@ _24 jan 2024_
|
|
|
176
192
|
- Fixed issue with setting mount, pivot and scale values to zero (0) in object literal with x and y key
|
|
177
193
|
- Added automatic mapping of ref string to each item in a for-loop
|
|
178
194
|
|
|
179
|
-
|
|
195
|
+
## v0.6.5
|
|
180
196
|
|
|
181
197
|
_16 jan 2024_
|
|
182
198
|
|
|
183
199
|
- Added `path` to boilerplate vite.config.js for deployments in a sub folder
|
|
184
200
|
- Improved error handling in the template parser, with more contextual error messages
|
|
185
201
|
|
|
186
|
-
|
|
202
|
+
## v0.6.4
|
|
187
203
|
|
|
188
204
|
_15 jan 2024_
|
|
189
205
|
|
|
190
206
|
- Added fix for sprites not working on certain devices
|
|
191
207
|
|
|
192
|
-
|
|
208
|
+
## v0.6.3
|
|
193
209
|
|
|
194
210
|
_12 jan 2024_
|
|
195
211
|
|
|
196
212
|
- Removed prepending protocol and host from sprite image
|
|
197
213
|
|
|
198
214
|
|
|
199
|
-
|
|
215
|
+
## v0.6.2
|
|
200
216
|
|
|
201
217
|
_12 jan 2024_
|
|
202
218
|
|
|
203
219
|
- Fixed issue with Sprites not working correctly due to missing background color
|
|
204
220
|
|
|
205
|
-
|
|
221
|
+
## v0.6.1
|
|
206
222
|
|
|
207
223
|
_8 jan 2024_
|
|
208
224
|
|
|
209
225
|
- Fixed issue with using single quotes as Text content
|
|
210
226
|
- Added first Text-to-Speech / Announcer functionality
|
|
211
227
|
|
|
212
|
-
|
|
228
|
+
## v0.6.0
|
|
213
229
|
|
|
214
230
|
_4 jan 2024_
|
|
215
231
|
|
|
216
232
|
- Added pre-compilation functionality to improve performance. Requires an update to the `vite.config.js` to enable. Read more details in this [blog post](https://lightningjs.io/blogs/blitsPreCompilation.html)
|
|
217
233
|
- Added `defaultFont` to the Launch settings
|
|
218
234
|
|
|
219
|
-
|
|
235
|
+
## v0.5.10
|
|
220
236
|
|
|
221
237
|
_3 jan 2024_
|
|
222
238
|
|
|
223
239
|
- Updated and improved documentation
|
|
224
240
|
- Added `screenResolution` and `pixelRatio` options to settings
|
|
225
241
|
|
|
226
|
-
|
|
242
|
+
## v0.5.9
|
|
227
243
|
|
|
228
244
|
_21 dec 2023_
|
|
229
245
|
|
|
@@ -234,13 +250,13 @@ _21 dec 2023_
|
|
|
234
250
|
- Added functionality to override route options during navigation
|
|
235
251
|
- Upgraded to latest version of the renderer (0.6.1) which contains a fix for animations not finishing correctly
|
|
236
252
|
|
|
237
|
-
|
|
253
|
+
## v0.5.8
|
|
238
254
|
|
|
239
255
|
_15 dec 2023_
|
|
240
256
|
|
|
241
257
|
- Internal refactor of the `Element`
|
|
242
258
|
|
|
243
|
-
|
|
259
|
+
## v0.5.7
|
|
244
260
|
|
|
245
261
|
_13 dec 2023_
|
|
246
262
|
|
|
@@ -248,39 +264,39 @@ _13 dec 2023_
|
|
|
248
264
|
- Linked effects directly to the available shaders exposed by the L3 renderer (starting 0.6.0)
|
|
249
265
|
- Added setting `reactivityMode` to control whether `Proxy` (default) or `defineProperty` is used to trigger reactive side effects
|
|
250
266
|
|
|
251
|
-
|
|
267
|
+
## v0.5.6
|
|
252
268
|
|
|
253
269
|
_11 dec 2023_
|
|
254
270
|
|
|
255
271
|
- Upgraded to version 0.6.0 of the Lightning 3 renderer
|
|
256
272
|
|
|
257
|
-
|
|
273
|
+
## v0.5.5
|
|
258
274
|
|
|
259
275
|
_5 dec 2023_
|
|
260
276
|
|
|
261
277
|
- Fixed regression in Slots functionality caused by forloop cleanup fix in 0.5.4
|
|
262
278
|
|
|
263
|
-
|
|
279
|
+
## v0.5.4
|
|
264
280
|
|
|
265
281
|
_5 dec 2023_
|
|
266
282
|
|
|
267
283
|
- Fixed issue with Components and Elements not always being cleaned up in forloop
|
|
268
284
|
- Added support for nested children inside a forloop on an Element
|
|
269
285
|
|
|
270
|
-
|
|
286
|
+
## v0.5.3
|
|
271
287
|
|
|
272
288
|
_4 dec 2023_
|
|
273
289
|
|
|
274
290
|
- Added transition `start` and tranition `end` callbacks
|
|
275
291
|
|
|
276
|
-
|
|
292
|
+
## v0.5.2
|
|
277
293
|
|
|
278
294
|
_30 nov 2023_
|
|
279
295
|
|
|
280
296
|
- Fixed issue in code generator leading to creation unnecessary child nodes
|
|
281
297
|
- Added focus handler to router view (that passes focus to the current active page)
|
|
282
298
|
|
|
283
|
-
|
|
299
|
+
## v0.5.1
|
|
284
300
|
|
|
285
301
|
_29 nov 2023_
|
|
286
302
|
|
|
@@ -288,20 +304,20 @@ _29 nov 2023_
|
|
|
288
304
|
- Added fastforward of transitions on the same property
|
|
289
305
|
- Added functionality to skip focus change on key hold
|
|
290
306
|
|
|
291
|
-
|
|
307
|
+
## v0.5.0
|
|
292
308
|
|
|
293
309
|
_23 nov 2023_
|
|
294
310
|
|
|
295
311
|
- Introduced `wordwrap` and `maxlines` attributes on the Text-component, replacing the previous `w` and `h` attributes (breaking change!)
|
|
296
312
|
|
|
297
|
-
|
|
313
|
+
## v0.4.2
|
|
298
314
|
|
|
299
315
|
_22 nov 2023_
|
|
300
316
|
|
|
301
317
|
- Improved parser and added more template validation (i.e. one single root element in a template)
|
|
302
318
|
- Fixed typo in documentation
|
|
303
319
|
|
|
304
|
-
|
|
320
|
+
## v0.4.1
|
|
305
321
|
|
|
306
322
|
_13 nov 2023_
|
|
307
323
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightningjs/blits",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
4
4
|
"description": "Blits: The Lightning 3 App Development Framework",
|
|
5
5
|
"bin": "bin/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"tape": "^5.5.0"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@lightningjs/renderer": "^0.8.
|
|
48
|
+
"@lightningjs/renderer": "^0.8.2",
|
|
49
49
|
"@lightningjs/vite-plugin-import-chunk-url": "^0.3.0",
|
|
50
50
|
"execa": "^8.0.1",
|
|
51
51
|
"kolorist": "^1.8.0",
|
package/src/application.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
/*
|
|
2
3
|
* Copyright 2023 Comcast Cable Communications Management, LLC
|
|
3
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -91,6 +92,10 @@ declare namespace Application {
|
|
|
91
92
|
[K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>
|
|
92
93
|
}[keyof T]
|
|
93
94
|
|
|
95
|
+
interface RouteHooks {
|
|
96
|
+
before?: (to: Route, from: Route) => string | Route;
|
|
97
|
+
}
|
|
98
|
+
|
|
94
99
|
type Route = {
|
|
95
100
|
/**
|
|
96
101
|
* URI path for the route
|
|
@@ -115,6 +120,26 @@ declare namespace Application {
|
|
|
115
120
|
* politeness level
|
|
116
121
|
*/
|
|
117
122
|
announce?: String | RouteAnnounce
|
|
123
|
+
/**
|
|
124
|
+
* Register hooks for the route
|
|
125
|
+
*/
|
|
126
|
+
hooks?: RouteHooks
|
|
127
|
+
/**
|
|
128
|
+
* Route path parameters
|
|
129
|
+
*/
|
|
130
|
+
readonly params?: {
|
|
131
|
+
[key: string]: string | number
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Allows for attaching custom data to a route, either hardcoded in the
|
|
135
|
+
* route definition or asigned to the route object in a before hook
|
|
136
|
+
*
|
|
137
|
+
* Will be merged with the route params and navigation data and passed as
|
|
138
|
+
* props into the route component
|
|
139
|
+
*/
|
|
140
|
+
data?: {
|
|
141
|
+
[key: string]: any
|
|
142
|
+
}
|
|
118
143
|
}
|
|
119
144
|
|
|
120
145
|
export interface ApplicationInstance extends ComponentInstance {}
|
package/src/component.js
CHANGED
|
@@ -68,7 +68,7 @@ const Component = (name = required('name'), config = required('config')) => {
|
|
|
68
68
|
if (config.methods) setupMethods(component, config.methods)
|
|
69
69
|
|
|
70
70
|
// setup state
|
|
71
|
-
|
|
71
|
+
setupState(component, config.state)
|
|
72
72
|
|
|
73
73
|
// setup computed
|
|
74
74
|
if (config.computed) setupComputed(component, config.computed)
|
|
@@ -218,7 +218,7 @@ const generateForLoopCode = function (templateObject, parent) {
|
|
|
218
218
|
ctx.renderCode.push(`parent = ${parent}`)
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
const
|
|
221
|
+
const forStartCounter = counter
|
|
222
222
|
|
|
223
223
|
// reference all reactive attributes (except those referencing the iterator item),
|
|
224
224
|
// to ensure that reactivity is registered, even when the initial array is empty
|
|
@@ -282,12 +282,15 @@ const generateForLoopCode = function (templateObject, parent) {
|
|
|
282
282
|
ctx.renderCode = ctx.renderCode.concat(ctx.effectsCode)
|
|
283
283
|
ctx.renderCode.push('}')
|
|
284
284
|
|
|
285
|
+
const forEndCounter = counter
|
|
285
286
|
ctx.renderCode.push(`
|
|
286
|
-
if(elms[${
|
|
287
|
-
Object.keys(elms[${
|
|
287
|
+
if(elms[${forStartCounter}]) {
|
|
288
|
+
Object.keys(elms[${forStartCounter}]).forEach(key => {
|
|
288
289
|
if(keys.indexOf(key) === -1) {
|
|
289
|
-
|
|
290
|
-
|
|
290
|
+
for(let i=${forStartCounter}; i <= ${forEndCounter}; i++){
|
|
291
|
+
elms[i][key].destroy && elms[i][key].destroy()
|
|
292
|
+
delete elms[i][key]
|
|
293
|
+
}
|
|
291
294
|
}
|
|
292
295
|
})
|
|
293
296
|
}
|
|
@@ -32,6 +32,11 @@ const getRaw = (value) => {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const reactiveProxy = (original, _parent = null, _key) => {
|
|
35
|
+
// don't create a proxy when a Blits component is assigned to a state variable
|
|
36
|
+
if (typeof original === 'object' && original[symbols.id]) {
|
|
37
|
+
return original
|
|
38
|
+
}
|
|
39
|
+
|
|
35
40
|
// if original object is already a proxy, don't create a new one but return the existing one instead
|
|
36
41
|
const existingProxy = getProxy(original)
|
|
37
42
|
if (existingProxy) {
|
|
@@ -89,7 +94,11 @@ const reactiveProxy = (original, _parent = null, _key) => {
|
|
|
89
94
|
result = Reflect.set(target, key, value, receiver)
|
|
90
95
|
}
|
|
91
96
|
|
|
92
|
-
if (result && oldRawValue !==
|
|
97
|
+
if (result && oldRawValue !== rawValue) {
|
|
98
|
+
// if we're assigning an array key directly trigger reactivity on the parent key as well
|
|
99
|
+
if (Array.isArray(target) && key in target) {
|
|
100
|
+
trigger(_parent, _key, true)
|
|
101
|
+
}
|
|
93
102
|
trigger(target, key, true)
|
|
94
103
|
}
|
|
95
104
|
return result
|
package/src/lib/setup/state.js
CHANGED
|
@@ -19,7 +19,7 @@ import { Log } from '../log.js'
|
|
|
19
19
|
|
|
20
20
|
import symbols from '../symbols.js'
|
|
21
21
|
|
|
22
|
-
export default (component, state) => {
|
|
22
|
+
export default (component, state = () => {}) => {
|
|
23
23
|
component[symbols.stateKeys] = []
|
|
24
24
|
|
|
25
25
|
state = { ...state.apply(component.prototype), ...{ hasFocus: false } }
|
package/src/router/router.js
CHANGED
|
@@ -46,6 +46,9 @@ const normalizePath = (path) => {
|
|
|
46
46
|
.toLowerCase()
|
|
47
47
|
)
|
|
48
48
|
}
|
|
49
|
+
const isObject = (v) => typeof v === 'object' && v !== null
|
|
50
|
+
|
|
51
|
+
const isString = (v) => typeof v === 'string'
|
|
49
52
|
|
|
50
53
|
export const matchHash = (path, routes = []) => {
|
|
51
54
|
// remove trailing slashes
|
|
@@ -57,6 +60,7 @@ export const matchHash = (path, routes = []) => {
|
|
|
57
60
|
const route = routes[i]
|
|
58
61
|
route.path = normalizePath(route.path)
|
|
59
62
|
if (route.path === path) {
|
|
63
|
+
route.params = {}
|
|
60
64
|
matchingRoute = route
|
|
61
65
|
} else if (route.path.indexOf(':') > -1) {
|
|
62
66
|
// match dynamic route parts
|
|
@@ -96,6 +100,9 @@ export const matchHash = (path, routes = []) => {
|
|
|
96
100
|
|
|
97
101
|
if (matchingRoute) {
|
|
98
102
|
matchingRoute.options = { ...matchingRoute.options, ...overrideOptions }
|
|
103
|
+
if (!matchingRoute.data) {
|
|
104
|
+
matchingRoute.data = {}
|
|
105
|
+
}
|
|
99
106
|
currentRoute = matchingRoute
|
|
100
107
|
}
|
|
101
108
|
|
|
@@ -107,9 +114,20 @@ export const navigate = async function () {
|
|
|
107
114
|
if (this.parent[symbols.routes]) {
|
|
108
115
|
const previousRoute = currentRoute
|
|
109
116
|
const hash = getHash()
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
let route = matchHash(hash, this.parent[symbols.routes])
|
|
118
|
+
let beforeHookOutput
|
|
112
119
|
if (route) {
|
|
120
|
+
if (route.hooks) {
|
|
121
|
+
if (route.hooks.before) {
|
|
122
|
+
beforeHookOutput = await route.hooks.before(route, previousRoute)
|
|
123
|
+
if (isString(beforeHookOutput)) {
|
|
124
|
+
currentRoute = previousRoute
|
|
125
|
+
to(beforeHookOutput)
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
route = isObject(beforeHookOutput) ? beforeHookOutput : route
|
|
113
131
|
// add the previous route (technically still the current route at this point)
|
|
114
132
|
// into the history stack, unless navigating back or inHistory flag of route is false
|
|
115
133
|
if (navigatingBack === false && previousRoute && previousRoute.options.inHistory === true) {
|
|
@@ -134,8 +152,8 @@ export const navigate = async function () {
|
|
|
134
152
|
holder.populate({})
|
|
135
153
|
holder.set('w', '100%')
|
|
136
154
|
holder.set('h', '100%')
|
|
137
|
-
// merge props with potential route params to be injected into the component instance
|
|
138
|
-
const props = { ...this[symbols.props], ...route.params, ...navigationData }
|
|
155
|
+
// merge props with potential route params, navigation data and route data to be injected into the component instance
|
|
156
|
+
const props = { ...this[symbols.props], ...route.params, ...navigationData, ...route.data }
|
|
139
157
|
|
|
140
158
|
view = await route.component({ props }, holder, this)
|
|
141
159
|
if (view[Symbol.toStringTag] === 'Module') {
|