@lightningjs/blits 0.3.15 → 0.4.0
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 +14 -0
- package/boilerplate/package.json +1 -1
- package/package.json +4 -3
- package/src/application.d.ts +70 -3
- package/src/application.js +6 -3
- package/src/component.js +25 -17
- package/src/components/RouterView.js +2 -2
- package/src/components/Sprite.js +4 -2
- package/src/element.js +12 -10
- package/src/focus.js +11 -7
- package/src/lib/codegenerator/generator.js +9 -9
- package/src/lib/codegenerator/generator.test_.js +25 -25
- package/src/lib/hooks.js +10 -1
- package/src/lib/reactivity/effect.js +2 -2
- package/src/lib/setup/base.js +36 -15
- package/src/lib/setup/computed.js +10 -5
- package/src/lib/setup/input.js +4 -2
- package/src/lib/setup/methods.js +5 -3
- package/src/lib/setup/props.js +7 -5
- package/src/lib/setup/props.test.js +17 -19
- package/src/lib/setup/routes.js +4 -2
- package/src/lib/setup/state.js +8 -6
- package/src/lib/setup/watch.js +6 -4
- package/src/lib/symbols.js +41 -0
- package/src/lib/templateparser/parser.js +13 -11
- package/src/router/router.js +166 -0
- package/src/router/transitions/fadeIn.js +27 -0
- package/src/router/transitions/fadeInOut.js +33 -0
- package/src/router/transitions/index.js +21 -0
- package/src/router/transitions/slideIn.js +28 -0
- package/src/router/transitions/slideInOut.js +33 -0
- package/src/router.js +18 -13
- package/src/settings.js +9 -3
- /package/boilerplate/{.eslintrc.js → .eslintrc.cjs} +0 -0
|
@@ -107,7 +107,7 @@ test('Generate render and effect code for a template with a single simple elemen
|
|
|
107
107
|
function anonymous(parent,component,context) {
|
|
108
108
|
const elms = []
|
|
109
109
|
|
|
110
|
-
elms[1] = this.element({componentId: component.
|
|
110
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
111
111
|
const elementConfig1 = {}
|
|
112
112
|
|
|
113
113
|
elementConfig1['type'] = "Component"
|
|
@@ -149,7 +149,7 @@ test('Generate code for a template with a simple element and a simple nested ele
|
|
|
149
149
|
function anonymous(parent,component,context) {
|
|
150
150
|
const elms = []
|
|
151
151
|
|
|
152
|
-
elms[1] = this.element({componentId: component.
|
|
152
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
153
153
|
const elementConfig1 = {}
|
|
154
154
|
|
|
155
155
|
elementConfig1['type'] = "Component"
|
|
@@ -158,7 +158,7 @@ test('Generate code for a template with a simple element and a simple nested ele
|
|
|
158
158
|
|
|
159
159
|
parent = elms[1]
|
|
160
160
|
|
|
161
|
-
elms[2] = this.element({componentId: component.
|
|
161
|
+
elms[2] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
162
162
|
const elementConfig2 = {}
|
|
163
163
|
|
|
164
164
|
elementConfig2['type'] = "Element"
|
|
@@ -198,7 +198,7 @@ test('Generate code for a template with a single element with attributes', (asse
|
|
|
198
198
|
function anonymous(parent,component,context) {
|
|
199
199
|
const elms = []
|
|
200
200
|
|
|
201
|
-
elms[1] = this.element({componentId: component.
|
|
201
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
202
202
|
const elementConfig1 = {}
|
|
203
203
|
|
|
204
204
|
elementConfig1['type'] = "Component"
|
|
@@ -246,7 +246,7 @@ test('Generate code for a template with attributes and a nested element with att
|
|
|
246
246
|
function anonymous(parent,component,context) {
|
|
247
247
|
const elms = []
|
|
248
248
|
|
|
249
|
-
elms[1] = this.element({componentId: component.
|
|
249
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
250
250
|
const elementConfig1 = {}
|
|
251
251
|
|
|
252
252
|
elementConfig1['type'] = "Component"
|
|
@@ -257,7 +257,7 @@ test('Generate code for a template with attributes and a nested element with att
|
|
|
257
257
|
|
|
258
258
|
parent = elms[1]
|
|
259
259
|
|
|
260
|
-
elms[2] = this.element({componentId: component.
|
|
260
|
+
elms[2] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
261
261
|
const elementConfig2 = {}
|
|
262
262
|
|
|
263
263
|
elementConfig2['type'] = "Element"
|
|
@@ -313,7 +313,7 @@ test('Generate code for a template with attributes and 2 nested elements with at
|
|
|
313
313
|
function anonymous(parent,component,context) {
|
|
314
314
|
const elms = []
|
|
315
315
|
|
|
316
|
-
elms[1] = this.element({componentId: component.
|
|
316
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
317
317
|
const elementConfig1 = {}
|
|
318
318
|
|
|
319
319
|
elementConfig1['type'] = "Component"
|
|
@@ -324,7 +324,7 @@ test('Generate code for a template with attributes and 2 nested elements with at
|
|
|
324
324
|
|
|
325
325
|
parent = elms[1]
|
|
326
326
|
|
|
327
|
-
elms[2] = this.element({componentId: component.
|
|
327
|
+
elms[2] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
328
328
|
const elementConfig2 = {}
|
|
329
329
|
|
|
330
330
|
elementConfig2['type'] = "Element"
|
|
@@ -336,7 +336,7 @@ test('Generate code for a template with attributes and 2 nested elements with at
|
|
|
336
336
|
|
|
337
337
|
parent = elms[1]
|
|
338
338
|
|
|
339
|
-
elms[3] = this.element({componentId: component.
|
|
339
|
+
elms[3] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
340
340
|
const elementConfig3 = {}
|
|
341
341
|
|
|
342
342
|
elementConfig3['type'] = "Element"
|
|
@@ -403,7 +403,7 @@ test('Generate code for a template with attributes and deep nested elements with
|
|
|
403
403
|
function anonymous(parent,component,context) {
|
|
404
404
|
const elms = []
|
|
405
405
|
|
|
406
|
-
elms[1] = this.element({componentId: component.
|
|
406
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
407
407
|
const elementConfig1 = {}
|
|
408
408
|
|
|
409
409
|
elementConfig1['type'] = "Component"
|
|
@@ -414,7 +414,7 @@ test('Generate code for a template with attributes and deep nested elements with
|
|
|
414
414
|
|
|
415
415
|
parent = elms[1]
|
|
416
416
|
|
|
417
|
-
elms[2] = this.element({componentId: component.
|
|
417
|
+
elms[2] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
418
418
|
const elementConfig2 = {}
|
|
419
419
|
|
|
420
420
|
elementConfig2['type'] = "Element"
|
|
@@ -426,7 +426,7 @@ test('Generate code for a template with attributes and deep nested elements with
|
|
|
426
426
|
|
|
427
427
|
parent = elms[1]
|
|
428
428
|
|
|
429
|
-
elms[3] = this.element({componentId: component.
|
|
429
|
+
elms[3] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
430
430
|
const elementConfig3 = {}
|
|
431
431
|
|
|
432
432
|
elementConfig3['type'] = "Element"
|
|
@@ -438,7 +438,7 @@ test('Generate code for a template with attributes and deep nested elements with
|
|
|
438
438
|
|
|
439
439
|
parent = elms[3]
|
|
440
440
|
|
|
441
|
-
elms[4] = this.element({componentId: component.
|
|
441
|
+
elms[4] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
442
442
|
const elementConfig4 = {}
|
|
443
443
|
|
|
444
444
|
elementConfig4['type'] = "Element"
|
|
@@ -448,7 +448,7 @@ test('Generate code for a template with attributes and deep nested elements with
|
|
|
448
448
|
|
|
449
449
|
parent = elms[3]
|
|
450
450
|
|
|
451
|
-
elms[5] = this.element({componentId: component.
|
|
451
|
+
elms[5] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
452
452
|
const elementConfig5 = {}
|
|
453
453
|
|
|
454
454
|
elementConfig5['type'] = "Element"
|
|
@@ -492,7 +492,7 @@ test('Generate code for a template with simple dynamic attributes', (assert) =>
|
|
|
492
492
|
function anonymous(parent,component,context) {
|
|
493
493
|
const elms = []
|
|
494
494
|
|
|
495
|
-
elms[1] = this.element({componentId: component.
|
|
495
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
496
496
|
const elementConfig1 = {}
|
|
497
497
|
|
|
498
498
|
elementConfig1['type'] = "Component"
|
|
@@ -559,7 +559,7 @@ test('Generate code for a template with an attribute with a dash', (assert) => {
|
|
|
559
559
|
function anonymous(parent,component,context) {
|
|
560
560
|
const elms = []
|
|
561
561
|
|
|
562
|
-
elms[1] = this.element({componentId: component.
|
|
562
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
563
563
|
const elementConfig1 = {}
|
|
564
564
|
|
|
565
565
|
elementConfig1['type'] = "Component"
|
|
@@ -604,7 +604,7 @@ test('Generate code for a template with dynamic attributes with code to be evalu
|
|
|
604
604
|
function anonymous(parent,component,context) {
|
|
605
605
|
const elms = []
|
|
606
606
|
|
|
607
|
-
elms[1] = this.element({componentId: component.
|
|
607
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
608
608
|
const elementConfig1 = {}
|
|
609
609
|
|
|
610
610
|
elementConfig1['type'] = "Component"
|
|
@@ -690,7 +690,7 @@ test('Generate code for a template with custom components', (assert) => {
|
|
|
690
690
|
function anonymous(parent,component,context) {
|
|
691
691
|
const elms = []
|
|
692
692
|
|
|
693
|
-
elms[1] = this.element({componentId: component.
|
|
693
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
694
694
|
const elementConfig1 = {}
|
|
695
695
|
|
|
696
696
|
elementConfig1['type'] = "Component"
|
|
@@ -746,7 +746,7 @@ test('Generate code for a template with an unregistered custom component', (asse
|
|
|
746
746
|
function anonymous(parent,component,context) {
|
|
747
747
|
const elms = []
|
|
748
748
|
|
|
749
|
-
elms[1] = this.element({componentId: component.
|
|
749
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
750
750
|
const elementConfig1 = {}
|
|
751
751
|
|
|
752
752
|
elementConfig1['type'] = "Component"
|
|
@@ -757,7 +757,7 @@ test('Generate code for a template with an unregistered custom component', (asse
|
|
|
757
757
|
|
|
758
758
|
parent = elms[1]
|
|
759
759
|
|
|
760
|
-
elms[3] = this.element({componentId: component.
|
|
760
|
+
elms[3] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
761
761
|
const elementConfig3 = {}
|
|
762
762
|
|
|
763
763
|
elementConfig3['type'] = "Poster2"
|
|
@@ -813,7 +813,7 @@ test('Generate code for a template with custom components with arguments', (asse
|
|
|
813
813
|
function anonymous(parent,component,context) {
|
|
814
814
|
const elms = []
|
|
815
815
|
|
|
816
|
-
elms[1] = this.element({componentId: component.
|
|
816
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
817
817
|
const elementConfig1 = {}
|
|
818
818
|
|
|
819
819
|
elementConfig1['type'] = "Component"
|
|
@@ -876,7 +876,7 @@ test('Generate code for a template with custom components with reactive props',
|
|
|
876
876
|
function anonymous(parent,component,context) {
|
|
877
877
|
const elms = []
|
|
878
878
|
|
|
879
|
-
elms[1] = this.element({componentId: component.
|
|
879
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
880
880
|
const elementConfig1 = {}
|
|
881
881
|
|
|
882
882
|
elementConfig1['type'] = "Component"
|
|
@@ -895,13 +895,13 @@ test('Generate code for a template with custom components with reactive props',
|
|
|
895
895
|
|
|
896
896
|
const expectedEffect1 = `
|
|
897
897
|
function anonymous(component,elms,context) {
|
|
898
|
-
elms[2].
|
|
898
|
+
elms[2][Symbol.for('props')].img = component.image
|
|
899
899
|
}
|
|
900
900
|
`
|
|
901
901
|
|
|
902
902
|
const expectedEffect2 = `
|
|
903
903
|
function anonymous(component,elms,context) {
|
|
904
|
-
elms[3].
|
|
904
|
+
elms[3][Symbol.for('props')].img = component.image
|
|
905
905
|
}
|
|
906
906
|
`
|
|
907
907
|
|
|
@@ -946,7 +946,7 @@ test('Generate code for a template with a transition attributes', (assert) => {
|
|
|
946
946
|
function anonymous(parent,component,context) {
|
|
947
947
|
const elms = []
|
|
948
948
|
|
|
949
|
-
elms[1] = this.element({componentId: component.
|
|
949
|
+
elms[1] = this.element({componentId: component[Symbol.for('id')], parentId: parent && parent.nodeId || 'root'})
|
|
950
950
|
const elementConfig1 = {}
|
|
951
951
|
|
|
952
952
|
elementConfig1['type'] = "Component"
|
package/src/lib/hooks.js
CHANGED
|
@@ -15,15 +15,24 @@
|
|
|
15
15
|
* SPDX-License-Identifier: Apache-2.0
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
import symbols from './symbols.js'
|
|
19
|
+
|
|
18
20
|
const cbs = {}
|
|
19
21
|
|
|
20
22
|
export const emit = (hook, name, scope) => {
|
|
21
23
|
cbs[name] && cbs[name][hook] && cbs[name][hook].apply(scope)
|
|
22
24
|
}
|
|
23
25
|
|
|
26
|
+
export const privateEmit = (hook, name, scope) => {
|
|
27
|
+
const symHook = symbols[hook]
|
|
28
|
+
cbs[name] && cbs[name][symHook] && cbs[name][symHook].apply(scope)
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
export const registerHooks = (hooks = {}, name) => {
|
|
25
32
|
cbs[name] = {}
|
|
26
|
-
|
|
33
|
+
// Combines enumerable keys and symbol properties of the 'hooks' object
|
|
34
|
+
const hookKeys = [...Object.keys(hooks), ...Object.getOwnPropertySymbols(hooks)]
|
|
35
|
+
hookKeys.forEach((hook) => {
|
|
27
36
|
if (typeof hooks[hook] === 'function') cbs[name][hook] = hooks[hook]
|
|
28
37
|
})
|
|
29
38
|
}
|
|
@@ -34,7 +34,7 @@ export const track = (target, key) => {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export const trigger = (target, key) => {
|
|
37
|
+
export const trigger = (target, key, force = false) => {
|
|
38
38
|
const effectsMap = objectMap.get(target)
|
|
39
39
|
if (!effectsMap) {
|
|
40
40
|
return
|
|
@@ -42,7 +42,7 @@ export const trigger = (target, key) => {
|
|
|
42
42
|
const effects = effectsMap.get(key)
|
|
43
43
|
if (effects) {
|
|
44
44
|
effects.forEach((effect) => {
|
|
45
|
-
effect()
|
|
45
|
+
effect(force)
|
|
46
46
|
})
|
|
47
47
|
}
|
|
48
48
|
}
|
package/src/lib/setup/base.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import { renderer } from '../../launch.js'
|
|
19
19
|
import Focus from '../../focus.js'
|
|
20
|
-
import { to } from '../../router.js'
|
|
20
|
+
import { to, currentRoute, navigating } from '../../router/router.js'
|
|
21
21
|
import Image from '../../components/Image.js'
|
|
22
22
|
import Circle from '../../components/Circle.js'
|
|
23
23
|
import RouterView from '../../components/RouterView.js'
|
|
@@ -25,6 +25,9 @@ import Sprite from '../../components/Sprite.js'
|
|
|
25
25
|
import Text from '../../components/Text.js'
|
|
26
26
|
import eventListeners from '../eventListeners.js'
|
|
27
27
|
import { default as log, Log } from '../log.js'
|
|
28
|
+
import symbols from '../symbols.js'
|
|
29
|
+
|
|
30
|
+
import { trigger } from '../reactivity/effect.js'
|
|
28
31
|
|
|
29
32
|
const shaders = {
|
|
30
33
|
radius: 'radius',
|
|
@@ -59,14 +62,14 @@ export default (component) => {
|
|
|
59
62
|
destroy: {
|
|
60
63
|
value: function () {
|
|
61
64
|
this.lifecycle.state = 'destroy'
|
|
62
|
-
for (let i = 0; i < this.
|
|
63
|
-
clearTimeout(this.
|
|
65
|
+
for (let i = 0; i < this[symbols.timeouts].length; i++) {
|
|
66
|
+
clearTimeout(this[symbols.timeouts][i])
|
|
64
67
|
}
|
|
65
|
-
for (let i = 0; i < this.
|
|
66
|
-
clearInterval(this.
|
|
68
|
+
for (let i = 0; i < this[symbols.intervals].length; i++) {
|
|
69
|
+
clearInterval(this[symbols.intervals][i])
|
|
67
70
|
}
|
|
68
71
|
eventListeners.removeListeners(this)
|
|
69
|
-
deleteChildren(this.
|
|
72
|
+
deleteChildren(this[symbols.children])
|
|
70
73
|
Log.debug(`Destroyed component ${this.componentId}`)
|
|
71
74
|
},
|
|
72
75
|
writable: false,
|
|
@@ -76,7 +79,7 @@ export default (component) => {
|
|
|
76
79
|
select: {
|
|
77
80
|
value: function (ref) {
|
|
78
81
|
let selected = null
|
|
79
|
-
this.
|
|
82
|
+
this[symbols.children].forEach((child) => {
|
|
80
83
|
if (Array.isArray(child)) {
|
|
81
84
|
child.forEach((c) => {
|
|
82
85
|
if (c['ref'] === ref) selected = c
|
|
@@ -114,12 +117,21 @@ export default (component) => {
|
|
|
114
117
|
$router: {
|
|
115
118
|
value: {
|
|
116
119
|
to,
|
|
120
|
+
get currentRoute() {
|
|
121
|
+
return currentRoute
|
|
122
|
+
},
|
|
123
|
+
get routes() {
|
|
124
|
+
return component.prototype[symbols.routes]
|
|
125
|
+
},
|
|
126
|
+
get navigating() {
|
|
127
|
+
return navigating
|
|
128
|
+
},
|
|
117
129
|
},
|
|
118
130
|
writable: false,
|
|
119
131
|
enumerable: true,
|
|
120
132
|
configurable: false,
|
|
121
133
|
},
|
|
122
|
-
|
|
134
|
+
[symbols.components]: {
|
|
123
135
|
value: {
|
|
124
136
|
Image: Image(),
|
|
125
137
|
Circle: Circle(),
|
|
@@ -131,7 +143,7 @@ export default (component) => {
|
|
|
131
143
|
enumerable: false,
|
|
132
144
|
configurable: false,
|
|
133
145
|
},
|
|
134
|
-
|
|
146
|
+
[symbols.timeouts]: {
|
|
135
147
|
value: [],
|
|
136
148
|
writable: false,
|
|
137
149
|
enumerable: false,
|
|
@@ -141,20 +153,20 @@ export default (component) => {
|
|
|
141
153
|
value: function (fn, ms, ...params) {
|
|
142
154
|
const timeoutId = setTimeout(
|
|
143
155
|
() => {
|
|
144
|
-
this.
|
|
156
|
+
this[symbols._timeouts] = this[symbols.timeouts].filter((id) => id !== timeoutId)
|
|
145
157
|
fn.apply(null, params)
|
|
146
158
|
},
|
|
147
159
|
ms,
|
|
148
160
|
params
|
|
149
161
|
)
|
|
150
|
-
this.
|
|
162
|
+
this[symbols.timeouts].push(timeoutId)
|
|
151
163
|
return timeoutId
|
|
152
164
|
},
|
|
153
165
|
writable: false,
|
|
154
166
|
enumerable: true,
|
|
155
167
|
configurable: false,
|
|
156
168
|
},
|
|
157
|
-
|
|
169
|
+
[symbols.intervals]: {
|
|
158
170
|
value: [],
|
|
159
171
|
writable: false,
|
|
160
172
|
enumerable: false,
|
|
@@ -164,13 +176,13 @@ export default (component) => {
|
|
|
164
176
|
value: function (fn, ms, ...params) {
|
|
165
177
|
const intervalId = setInterval(
|
|
166
178
|
() => {
|
|
167
|
-
this.
|
|
179
|
+
this[symbols._intervals] = this[symbols.intervals].filter((id) => id !== intervalId)
|
|
168
180
|
fn.apply(null, params)
|
|
169
181
|
},
|
|
170
182
|
ms,
|
|
171
183
|
params
|
|
172
184
|
)
|
|
173
|
-
this.
|
|
185
|
+
this[symbols.intervals].push(intervalId)
|
|
174
186
|
return intervalId
|
|
175
187
|
},
|
|
176
188
|
writable: false,
|
|
@@ -193,7 +205,7 @@ export default (component) => {
|
|
|
193
205
|
enumerable: true,
|
|
194
206
|
configurable: false,
|
|
195
207
|
},
|
|
196
|
-
|
|
208
|
+
[symbols.renderer]: {
|
|
197
209
|
value: renderer,
|
|
198
210
|
writable: false,
|
|
199
211
|
enumerable: false,
|
|
@@ -205,6 +217,15 @@ export default (component) => {
|
|
|
205
217
|
enumerable: false,
|
|
206
218
|
configurable: false,
|
|
207
219
|
},
|
|
220
|
+
$trigger: {
|
|
221
|
+
value: function (key) {
|
|
222
|
+
// trigger with force set to true
|
|
223
|
+
trigger(this[symbols.originalState], key, true)
|
|
224
|
+
},
|
|
225
|
+
writable: false,
|
|
226
|
+
enumerable: false,
|
|
227
|
+
configurable: false,
|
|
228
|
+
},
|
|
208
229
|
})
|
|
209
230
|
}
|
|
210
231
|
|
|
@@ -17,22 +17,27 @@
|
|
|
17
17
|
|
|
18
18
|
import { Log } from '../log.js'
|
|
19
19
|
|
|
20
|
+
import symbols from '../symbols.js'
|
|
21
|
+
|
|
20
22
|
export default (component, computeds) => {
|
|
21
|
-
component.
|
|
23
|
+
component[symbols.computedKeys] = []
|
|
22
24
|
|
|
23
25
|
for (let computed in computeds) {
|
|
24
26
|
// test for reserved keys?
|
|
25
|
-
if (component.
|
|
27
|
+
if (component[symbols.stateKeys] && component[symbols.stateKeys].indexOf(computed) > -1) {
|
|
26
28
|
Log.error(`${computed} already exists as a prop`)
|
|
27
|
-
} else if (component.
|
|
29
|
+
} else if (component[symbols.propKeys] && component[symbols.propKeys].indexOf(computed) > -1) {
|
|
28
30
|
Log.error(`${computed} already exists as a prop`)
|
|
29
|
-
} else if (
|
|
31
|
+
} else if (
|
|
32
|
+
component[symbols.methodKeys] &&
|
|
33
|
+
component[symbols.methodKeys].indexOf(computed) > -1
|
|
34
|
+
) {
|
|
30
35
|
Log.error(`${computed} already exists as a method`)
|
|
31
36
|
} else {
|
|
32
37
|
if (typeof computeds[computed] !== 'function') {
|
|
33
38
|
Log.warn(`${computed} is not a function`)
|
|
34
39
|
}
|
|
35
|
-
component.
|
|
40
|
+
component[symbols.computedKeys].push(computed)
|
|
36
41
|
Object.defineProperty(component.prototype, computed, {
|
|
37
42
|
get() {
|
|
38
43
|
return computeds[computed].apply(this)
|
package/src/lib/setup/input.js
CHANGED
|
@@ -17,12 +17,14 @@
|
|
|
17
17
|
|
|
18
18
|
import { Log } from '../log.js'
|
|
19
19
|
|
|
20
|
+
import symbols from '../symbols.js'
|
|
21
|
+
|
|
20
22
|
export default (component, input) => {
|
|
21
|
-
component.prototype.
|
|
23
|
+
component.prototype[symbols.inputEvents] = []
|
|
22
24
|
Object.keys(input).forEach((key) => {
|
|
23
25
|
if (typeof input[key] !== 'function') {
|
|
24
26
|
Log.warn(`${input[key]} is not a function`)
|
|
25
27
|
}
|
|
26
|
-
component.prototype.
|
|
28
|
+
component.prototype[symbols.inputEvents][key] = input[key]
|
|
27
29
|
})
|
|
28
30
|
}
|
package/src/lib/setup/methods.js
CHANGED
|
@@ -17,18 +17,20 @@
|
|
|
17
17
|
|
|
18
18
|
import { Log } from '../log.js'
|
|
19
19
|
|
|
20
|
+
import symbols from '../symbols.js'
|
|
21
|
+
|
|
20
22
|
export default (component, methods) => {
|
|
21
|
-
component.
|
|
23
|
+
component[symbols.methodKeys] = []
|
|
22
24
|
|
|
23
25
|
for (let method in methods) {
|
|
24
26
|
// test for reserved keys?
|
|
25
|
-
if (component.
|
|
27
|
+
if (component[symbols.propKeys] && component[symbols.propKeys].indexOf(method) > -1) {
|
|
26
28
|
Log.error(`${method} already exists as a prop`)
|
|
27
29
|
} else {
|
|
28
30
|
if (typeof methods[method] !== 'function') {
|
|
29
31
|
Log.warn(`${method} is not a function`)
|
|
30
32
|
}
|
|
31
|
-
component.
|
|
33
|
+
component[symbols.methodKeys].push(method)
|
|
32
34
|
component.prototype[method] = methods[method]
|
|
33
35
|
}
|
|
34
36
|
}
|
package/src/lib/setup/props.js
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { Log } from '../log.js'
|
|
19
19
|
|
|
20
|
+
import symbols from '../symbols.js'
|
|
21
|
+
|
|
20
22
|
const baseProp = {
|
|
21
23
|
cast: (v) => v,
|
|
22
24
|
required: false,
|
|
@@ -26,15 +28,15 @@ export default (component, props = []) => {
|
|
|
26
28
|
if (props.indexOf('ref') === -1) {
|
|
27
29
|
props.push('ref')
|
|
28
30
|
}
|
|
29
|
-
component.
|
|
31
|
+
component[symbols.propKeys] = []
|
|
30
32
|
props.forEach((prop) => {
|
|
31
33
|
prop = { ...baseProp, ...(typeof prop === 'object' ? prop : { key: prop }) }
|
|
32
|
-
component.
|
|
34
|
+
component[symbols.propKeys].push(prop.key)
|
|
33
35
|
Object.defineProperty(component.prototype, prop.key, {
|
|
34
36
|
get() {
|
|
35
37
|
const value = prop.cast(
|
|
36
|
-
this.
|
|
37
|
-
? this.
|
|
38
|
+
this[symbols.props] && prop.key in this[symbols.props]
|
|
39
|
+
? this[symbols.props][prop.key]
|
|
38
40
|
: prop.default || undefined
|
|
39
41
|
)
|
|
40
42
|
|
|
@@ -46,7 +48,7 @@ export default (component, props = []) => {
|
|
|
46
48
|
},
|
|
47
49
|
set(v) {
|
|
48
50
|
Log.warn(`Warning! Avoid mutating props directly (${prop.key})`)
|
|
49
|
-
this.
|
|
51
|
+
this[symbols.props][prop.key] = v
|
|
50
52
|
},
|
|
51
53
|
})
|
|
52
54
|
})
|
|
@@ -19,6 +19,8 @@ import test from 'tape'
|
|
|
19
19
|
import propsFn from './props.js'
|
|
20
20
|
import { initLog } from '../log.js'
|
|
21
21
|
|
|
22
|
+
import symbols from '../symbols.js'
|
|
23
|
+
|
|
22
24
|
initLog()
|
|
23
25
|
|
|
24
26
|
test('Type props function', (assert) => {
|
|
@@ -29,16 +31,12 @@ test('Type props function', (assert) => {
|
|
|
29
31
|
assert.end()
|
|
30
32
|
})
|
|
31
33
|
|
|
32
|
-
test('
|
|
34
|
+
test('Has correct symbols', (assert) => {
|
|
33
35
|
const component = new Function()
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
assert.false(component.hasOwnProperty('___propKeys'), 'Component should not have a ___propKeys key')
|
|
37
|
-
|
|
38
|
-
propsFn(component)
|
|
39
|
-
|
|
36
|
+
const props = ['index', 'img', 'url']
|
|
37
|
+
propsFn(component, props)
|
|
40
38
|
/* eslint-disable */
|
|
41
|
-
assert.true(component.
|
|
39
|
+
assert.true(component[symbols.propKeys], 'Component should have a propKey symbol')
|
|
42
40
|
assert.end()
|
|
43
41
|
})
|
|
44
42
|
|
|
@@ -47,8 +45,8 @@ test('Pass props as an array', (assert) => {
|
|
|
47
45
|
const props = ['index', 'img', 'url']
|
|
48
46
|
propsFn(component, props)
|
|
49
47
|
|
|
50
|
-
assert.equal(props.length, component.
|
|
51
|
-
assert.equal(props.length, props.map(prop => component.
|
|
48
|
+
assert.equal(props.length, component[symbols.propKeys].length, 'All passed props should be stored on propKeys')
|
|
49
|
+
assert.equal(props.length, props.map(prop => component[symbols.propKeys].indexOf(prop) > -1).filter(prop => prop === true).length, 'All passed props should be stored on propKeys')
|
|
52
50
|
|
|
53
51
|
props.forEach((prop) => {
|
|
54
52
|
assert.true(typeof Object.getOwnPropertyDescriptor(component.prototype, prop).get === 'function', `A getter should have been created for property ${prop}`)
|
|
@@ -62,14 +60,14 @@ test('Get value of props', (assert) => {
|
|
|
62
60
|
const component = new Function()
|
|
63
61
|
|
|
64
62
|
const componentInstance = new component
|
|
65
|
-
componentInstance.
|
|
63
|
+
componentInstance[symbols.props] = {
|
|
66
64
|
index: 1,
|
|
67
65
|
img: 'lorem-ipsum.jpg',
|
|
68
66
|
url: 'http://localhost'
|
|
69
67
|
}
|
|
70
68
|
|
|
71
69
|
const componentInstance2 = new component
|
|
72
|
-
componentInstance2.
|
|
70
|
+
componentInstance2[symbols.props] = {
|
|
73
71
|
index: 2,
|
|
74
72
|
img: 'bla.jpg',
|
|
75
73
|
url: 'http://127.0.0.1'
|
|
@@ -79,8 +77,8 @@ test('Get value of props', (assert) => {
|
|
|
79
77
|
propsFn(component, props)
|
|
80
78
|
|
|
81
79
|
props.forEach((prop) => {
|
|
82
|
-
assert.equal(componentInstance[prop], componentInstance.
|
|
83
|
-
assert.equal(componentInstance2[prop], componentInstance2.
|
|
80
|
+
assert.equal(componentInstance[prop], componentInstance[symbols.props][prop], `The correct value of ${prop} should be returned via the getter`)
|
|
81
|
+
assert.equal(componentInstance2[prop], componentInstance2[symbols.props][prop], `The correct value of ${prop} should be returned via the getter`)
|
|
84
82
|
})
|
|
85
83
|
|
|
86
84
|
assert.equal(componentInstance['bla'], undefined, `Undefined should be returned if a prop doesn't exist`)
|
|
@@ -93,8 +91,8 @@ test('Passing props as an object', (assert) => {
|
|
|
93
91
|
const props = [{key: 'index'}, {key: 'img'}, {key: 'url'}]
|
|
94
92
|
propsFn(component, props)
|
|
95
93
|
|
|
96
|
-
assert.equal(props.length, component.
|
|
97
|
-
assert.equal(props.length, props.map(prop => component.
|
|
94
|
+
assert.equal(props.length, component[symbols.propKeys].length, 'All passed props should be stored on propKeys')
|
|
95
|
+
assert.equal(props.length, props.map(prop => component[symbols.propKeys].indexOf(typeof prop === 'object' ? prop.key : prop) > -1).filter(prop => prop === true).length, 'All passed props should be stored on propKeys')
|
|
98
96
|
|
|
99
97
|
props.forEach((prop) => {
|
|
100
98
|
assert.true(typeof Object.getOwnPropertyDescriptor(component.prototype, typeof prop === 'object' ? prop.key : prop).get === 'function', `A getter should have been created for property ${prop}`)
|
|
@@ -109,8 +107,8 @@ test('Passing props as an object mixed with single keys', (assert) => {
|
|
|
109
107
|
const props = [{key: 'index'}, 'img', {key: 'url'}]
|
|
110
108
|
propsFn(component, props)
|
|
111
109
|
|
|
112
|
-
assert.equal(props.length, component.
|
|
113
|
-
assert.equal(props.length, props.map(prop => component.
|
|
110
|
+
assert.equal(props.length, component[symbols.propKeys].length, 'All passed props should be stored on propKeys')
|
|
111
|
+
assert.equal(props.length, props.map(prop => component[symbols.propKeys].indexOf(typeof prop === 'object' ? prop.key : prop) > -1).filter(prop => prop === true).length, 'All passed props should be stored on propKeys')
|
|
114
112
|
|
|
115
113
|
props.forEach((prop) => {
|
|
116
114
|
assert.true(typeof Object.getOwnPropertyDescriptor(component.prototype, typeof prop === 'object' ? prop.key : prop).get === 'function', `A getter should have been created for property ${prop}`)
|
|
@@ -123,7 +121,7 @@ test('Casting props to a type', (assert) => {
|
|
|
123
121
|
const component = new Function()
|
|
124
122
|
|
|
125
123
|
const componentInstance = new component
|
|
126
|
-
componentInstance.
|
|
124
|
+
componentInstance[symbols.props] = {
|
|
127
125
|
number: '1',
|
|
128
126
|
string: 100,
|
|
129
127
|
boolean: true,
|
package/src/lib/setup/routes.js
CHANGED
|
@@ -15,10 +15,12 @@
|
|
|
15
15
|
* SPDX-License-Identifier: Apache-2.0
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
import symbols from '../symbols.js'
|
|
19
|
+
|
|
18
20
|
export default (component, routes) => {
|
|
19
|
-
component.prototype.
|
|
21
|
+
component.prototype[symbols.routes] = []
|
|
20
22
|
Object.keys(routes).forEach((key) => {
|
|
21
23
|
// todo: validate routes[key] for expected format etc.
|
|
22
|
-
component.prototype.
|
|
24
|
+
component.prototype[symbols.routes][key] = routes[key]
|
|
23
25
|
})
|
|
24
26
|
}
|