glass-easel-miniprogram-adapter 0.1.1 → 0.2.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/dist/glass_easel_miniprogram_adapter.js +1 -1
- package/dist/glass_easel_miniprogram_adapter.js.map +1 -1
- package/dist/types/src/backend.d.ts +8 -0
- package/dist/types/src/backend.d.ts.map +1 -1
- package/dist/types/src/behavior.d.ts +1 -1
- package/dist/types/src/behavior.d.ts.map +1 -1
- package/dist/types/src/component.d.ts +12 -2
- package/dist/types/src/component.d.ts.map +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/intersection.d.ts +24 -0
- package/dist/types/src/intersection.d.ts.map +1 -0
- package/dist/types/src/media_query.d.ts +13 -0
- package/dist/types/src/media_query.d.ts.map +1 -0
- package/dist/types/src/selector_query.d.ts.map +1 -1
- package/dist/types/src/space.d.ts +3 -3
- package/dist/types/src/space.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +4 -4
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/types/tests/base/env.d.ts.map +1 -1
- package/jest.config.js +1 -3
- package/package.json +2 -2
- package/src/backend.ts +20 -10
- package/src/behavior.ts +7 -29
- package/src/component.ts +56 -38
- package/src/index.ts +1 -3
- package/src/intersection.ts +119 -0
- package/src/media_query.ts +28 -0
- package/src/selector_query.ts +176 -174
- package/src/space.ts +154 -238
- package/src/types.ts +33 -33
- package/src/utils.ts +4 -3
- package/tests/base/env.ts +1 -2
- package/tests/data_update.test.ts +43 -37
- package/tests/env.test.ts +37 -37
- package/tests/selector.test.ts +295 -189
- package/tests/space.test.ts +216 -91
- package/tests/trait_behavior.test.ts +26 -23
- package/webpack.config.js +14 -13
package/tests/space.test.ts
CHANGED
|
@@ -21,11 +21,15 @@ describe('define', () => {
|
|
|
21
21
|
codeSpace.addStyleSheet('app', 'app.css')
|
|
22
22
|
codeSpace.addStyleSheet('path/to/comp', 'path/to/comp.css')
|
|
23
23
|
|
|
24
|
-
codeSpace.addCompiledTemplate(
|
|
24
|
+
codeSpace.addCompiledTemplate(
|
|
25
|
+
'path/to/comp',
|
|
26
|
+
tmpl(`
|
|
25
27
|
<div class="ab">{{a}}-{{b}}</div>
|
|
26
|
-
`)
|
|
28
|
+
`),
|
|
29
|
+
)
|
|
27
30
|
|
|
28
|
-
const beh = codeSpace
|
|
31
|
+
const beh = codeSpace
|
|
32
|
+
.behavior()
|
|
29
33
|
.definition({
|
|
30
34
|
data: {
|
|
31
35
|
a: 123,
|
|
@@ -33,7 +37,8 @@ describe('define', () => {
|
|
|
33
37
|
})
|
|
34
38
|
.register()
|
|
35
39
|
|
|
36
|
-
codeSpace
|
|
40
|
+
codeSpace
|
|
41
|
+
.component('path/to/comp')
|
|
37
42
|
.definition({
|
|
38
43
|
behaviors: [beh],
|
|
39
44
|
properties: {
|
|
@@ -56,11 +61,14 @@ describe('define', () => {
|
|
|
56
61
|
|
|
57
62
|
codeSpace.addComponentStaticConfig('path/to/comp', {})
|
|
58
63
|
|
|
59
|
-
codeSpace.addCompiledTemplate(
|
|
64
|
+
codeSpace.addCompiledTemplate(
|
|
65
|
+
'path/to/comp',
|
|
66
|
+
tmpl(`
|
|
60
67
|
<div>{{a}}-{{b}}-{{c}}</div>
|
|
61
|
-
`)
|
|
68
|
+
`),
|
|
69
|
+
)
|
|
62
70
|
|
|
63
|
-
const g = {} as { Behavior: BehaviorConstructor
|
|
71
|
+
const g = {} as { Behavior: BehaviorConstructor; Component: ComponentConstructor }
|
|
64
72
|
codeSpace.globalComponentEnv(g, 'path/to/comp', () => {
|
|
65
73
|
const Behavior = g.Behavior
|
|
66
74
|
const Component = g.Component
|
|
@@ -76,6 +84,8 @@ describe('define', () => {
|
|
|
76
84
|
},
|
|
77
85
|
})
|
|
78
86
|
|
|
87
|
+
const traitBeh = Behavior.trait<{ a: () => void }>()
|
|
88
|
+
|
|
79
89
|
Component({
|
|
80
90
|
options: {
|
|
81
91
|
propertyEarlyInit: true,
|
|
@@ -87,12 +97,14 @@ describe('define', () => {
|
|
|
87
97
|
data: () => ({
|
|
88
98
|
c: 789,
|
|
89
99
|
}),
|
|
90
|
-
observers: [
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
100
|
+
observers: [
|
|
101
|
+
{
|
|
102
|
+
fields: 'b',
|
|
103
|
+
observer() {
|
|
104
|
+
callOrder.push(2)
|
|
105
|
+
},
|
|
94
106
|
},
|
|
95
|
-
|
|
107
|
+
],
|
|
96
108
|
created() {
|
|
97
109
|
callOrder.push(3)
|
|
98
110
|
},
|
|
@@ -113,14 +125,20 @@ describe('define', () => {
|
|
|
113
125
|
callOrder.push(7)
|
|
114
126
|
},
|
|
115
127
|
lifetimes: {
|
|
116
|
-
invalid() {
|
|
128
|
+
invalid() {
|
|
129
|
+
/* empty */
|
|
130
|
+
},
|
|
117
131
|
},
|
|
118
132
|
pageLifetimes: {
|
|
119
|
-
invalid() {
|
|
133
|
+
invalid() {
|
|
134
|
+
/* empty */
|
|
135
|
+
},
|
|
120
136
|
},
|
|
121
137
|
relations: {
|
|
122
138
|
invalid: {
|
|
123
139
|
type: 'parent',
|
|
140
|
+
// FIXME the target should accept wrapped behaviors
|
|
141
|
+
target: traitBeh._$,
|
|
124
142
|
},
|
|
125
143
|
},
|
|
126
144
|
externalClasses: [],
|
|
@@ -143,9 +161,12 @@ describe('define', () => {
|
|
|
143
161
|
const codeSpace = env.createCodeSpace('', true)
|
|
144
162
|
const callOrder = [] as number[]
|
|
145
163
|
|
|
146
|
-
codeSpace.addCompiledTemplate(
|
|
164
|
+
codeSpace.addCompiledTemplate(
|
|
165
|
+
'path/to/comp',
|
|
166
|
+
tmpl(`
|
|
147
167
|
<div>{{a}}-{{b}}</div>
|
|
148
|
-
`)
|
|
168
|
+
`),
|
|
169
|
+
)
|
|
149
170
|
|
|
150
171
|
codeSpace.componentEnv('path/to/comp', ({ Behavior, Page }) => {
|
|
151
172
|
const beh = Behavior()
|
|
@@ -153,8 +174,8 @@ describe('define', () => {
|
|
|
153
174
|
.lifetime('attached', function () {
|
|
154
175
|
expect(this.hasBehavior(beh)).toBe(true)
|
|
155
176
|
const self = this as unknown as {
|
|
156
|
-
myMethod: () => number
|
|
157
|
-
myData: any
|
|
177
|
+
myMethod: () => number
|
|
178
|
+
myData: any
|
|
158
179
|
}
|
|
159
180
|
expect(self.myMethod()).toBe(123)
|
|
160
181
|
expect(self.myData).toStrictEqual({ myField: 456 })
|
|
@@ -189,13 +210,16 @@ describe('define', () => {
|
|
|
189
210
|
|
|
190
211
|
codeSpace.addComponentStaticConfig('comp/a', {
|
|
191
212
|
component: true,
|
|
192
|
-
|
|
213
|
+
componentGenerics: {
|
|
193
214
|
c: true,
|
|
194
215
|
},
|
|
195
216
|
})
|
|
196
|
-
codeSpace.addCompiledTemplate(
|
|
217
|
+
codeSpace.addCompiledTemplate(
|
|
218
|
+
'comp/a',
|
|
219
|
+
tmpl(`
|
|
197
220
|
<c />
|
|
198
|
-
`)
|
|
221
|
+
`),
|
|
222
|
+
)
|
|
199
223
|
codeSpace.componentEnv('comp/a', ({ Component }) => {
|
|
200
224
|
Component().register()
|
|
201
225
|
})
|
|
@@ -203,9 +227,12 @@ describe('define', () => {
|
|
|
203
227
|
codeSpace.addComponentStaticConfig('comp/b', {
|
|
204
228
|
component: true,
|
|
205
229
|
})
|
|
206
|
-
codeSpace.addCompiledTemplate(
|
|
230
|
+
codeSpace.addCompiledTemplate(
|
|
231
|
+
'comp/b',
|
|
232
|
+
tmpl(`
|
|
207
233
|
<span>B</span>
|
|
208
|
-
`)
|
|
234
|
+
`),
|
|
235
|
+
)
|
|
209
236
|
codeSpace.componentEnv('comp/b', ({ Component }) => {
|
|
210
237
|
Component().register()
|
|
211
238
|
})
|
|
@@ -216,9 +243,12 @@ describe('define', () => {
|
|
|
216
243
|
b: '/comp/b',
|
|
217
244
|
},
|
|
218
245
|
})
|
|
219
|
-
codeSpace.addCompiledTemplate(
|
|
246
|
+
codeSpace.addCompiledTemplate(
|
|
247
|
+
'path/to/comp',
|
|
248
|
+
tmpl(`
|
|
220
249
|
<a generic:c="b" />
|
|
221
|
-
`)
|
|
250
|
+
`),
|
|
251
|
+
)
|
|
222
252
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
223
253
|
Component().register()
|
|
224
254
|
})
|
|
@@ -235,9 +265,12 @@ describe('define', () => {
|
|
|
235
265
|
codeSpace.addComponentStaticConfig('comp/a', {
|
|
236
266
|
component: true,
|
|
237
267
|
})
|
|
238
|
-
codeSpace.addCompiledTemplate(
|
|
268
|
+
codeSpace.addCompiledTemplate(
|
|
269
|
+
'comp/a',
|
|
270
|
+
tmpl(`
|
|
239
271
|
<div>A</div>
|
|
240
|
-
`)
|
|
272
|
+
`),
|
|
273
|
+
)
|
|
241
274
|
codeSpace.componentEnv('comp/a', ({ Component }) => {
|
|
242
275
|
Component().register()
|
|
243
276
|
})
|
|
@@ -245,14 +278,18 @@ describe('define', () => {
|
|
|
245
278
|
codeSpace.addComponentStaticConfig('path/to/comp', {
|
|
246
279
|
usingComponents: {
|
|
247
280
|
a: '/comp/b',
|
|
281
|
+
ph: '/comp/a',
|
|
248
282
|
},
|
|
249
|
-
|
|
250
|
-
a: '
|
|
283
|
+
componentPlaceholder: {
|
|
284
|
+
a: 'ph',
|
|
251
285
|
},
|
|
252
286
|
})
|
|
253
|
-
codeSpace.addCompiledTemplate(
|
|
287
|
+
codeSpace.addCompiledTemplate(
|
|
288
|
+
'path/to/comp',
|
|
289
|
+
tmpl(`
|
|
254
290
|
<a />
|
|
255
|
-
`)
|
|
291
|
+
`),
|
|
292
|
+
)
|
|
256
293
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
257
294
|
Component().register()
|
|
258
295
|
})
|
|
@@ -264,9 +301,12 @@ describe('define', () => {
|
|
|
264
301
|
codeSpace.addComponentStaticConfig('comp/b', {
|
|
265
302
|
component: true,
|
|
266
303
|
})
|
|
267
|
-
codeSpace.addCompiledTemplate(
|
|
304
|
+
codeSpace.addCompiledTemplate(
|
|
305
|
+
'comp/b',
|
|
306
|
+
tmpl(`
|
|
268
307
|
<span>B</span>
|
|
269
|
-
`)
|
|
308
|
+
`),
|
|
309
|
+
)
|
|
270
310
|
codeSpace.componentEnv('comp/b', ({ Component }) => {
|
|
271
311
|
Component().register()
|
|
272
312
|
})
|
|
@@ -278,9 +318,12 @@ describe('define', () => {
|
|
|
278
318
|
const env = new MiniProgramEnv()
|
|
279
319
|
const codeSpace = env.createCodeSpace('', true)
|
|
280
320
|
|
|
281
|
-
codeSpace.addCompiledTemplate(
|
|
321
|
+
codeSpace.addCompiledTemplate(
|
|
322
|
+
'path/to/comp',
|
|
323
|
+
tmpl(`
|
|
282
324
|
<div>{{_a}}-{{b}}</div>
|
|
283
|
-
`)
|
|
325
|
+
`),
|
|
326
|
+
)
|
|
284
327
|
|
|
285
328
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
286
329
|
Component()
|
|
@@ -307,9 +350,12 @@ describe('define', () => {
|
|
|
307
350
|
pureDataPattern: '^_',
|
|
308
351
|
})
|
|
309
352
|
|
|
310
|
-
codeSpace.addCompiledTemplate(
|
|
353
|
+
codeSpace.addCompiledTemplate(
|
|
354
|
+
'path/to/comp',
|
|
355
|
+
tmpl(`
|
|
311
356
|
<div>{{_a}}-{{b}}</div>
|
|
312
|
-
`)
|
|
357
|
+
`),
|
|
358
|
+
)
|
|
313
359
|
|
|
314
360
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
315
361
|
Component()
|
|
@@ -337,9 +383,12 @@ describe('define', () => {
|
|
|
337
383
|
component: true,
|
|
338
384
|
addGlobalClass: true,
|
|
339
385
|
})
|
|
340
|
-
codeSpace.addCompiledTemplate(
|
|
386
|
+
codeSpace.addCompiledTemplate(
|
|
387
|
+
'child/comp',
|
|
388
|
+
tmpl(`
|
|
341
389
|
<div class="def"></div>
|
|
342
|
-
`)
|
|
390
|
+
`),
|
|
391
|
+
)
|
|
343
392
|
codeSpace.componentEnv('child/comp', ({ Component }) => {
|
|
344
393
|
Component()
|
|
345
394
|
.options({
|
|
@@ -354,11 +403,14 @@ describe('define', () => {
|
|
|
354
403
|
},
|
|
355
404
|
addGlobalClass: true,
|
|
356
405
|
})
|
|
357
|
-
codeSpace.addCompiledTemplate(
|
|
406
|
+
codeSpace.addCompiledTemplate(
|
|
407
|
+
'path/to/comp',
|
|
408
|
+
tmpl(`
|
|
358
409
|
<div class="abc">
|
|
359
410
|
<child />
|
|
360
411
|
</div>
|
|
361
|
-
`)
|
|
412
|
+
`),
|
|
413
|
+
)
|
|
362
414
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
363
415
|
Component().register()
|
|
364
416
|
})
|
|
@@ -366,7 +418,9 @@ describe('define', () => {
|
|
|
366
418
|
const ab = env.associateBackend()
|
|
367
419
|
ab.registerStyleSheetContent('empty-style-sheet', '')
|
|
368
420
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
369
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
421
|
+
expect(domHtml(root.getComponent())).toBe(
|
|
422
|
+
'<div class="abc"><div class="def child-comp--def"></div></div>',
|
|
423
|
+
)
|
|
370
424
|
})
|
|
371
425
|
|
|
372
426
|
test('options styleIsolation shared', () => {
|
|
@@ -378,9 +432,12 @@ describe('define', () => {
|
|
|
378
432
|
component: true,
|
|
379
433
|
styleIsolation: StyleIsolation.Shared,
|
|
380
434
|
})
|
|
381
|
-
codeSpace.addCompiledTemplate(
|
|
435
|
+
codeSpace.addCompiledTemplate(
|
|
436
|
+
'child/comp',
|
|
437
|
+
tmpl(`
|
|
382
438
|
<div class="def"></div>
|
|
383
|
-
`)
|
|
439
|
+
`),
|
|
440
|
+
)
|
|
384
441
|
codeSpace.componentEnv('child/comp', ({ Component }) => {
|
|
385
442
|
Component()
|
|
386
443
|
.options({
|
|
@@ -396,11 +453,14 @@ describe('define', () => {
|
|
|
396
453
|
},
|
|
397
454
|
styleIsolation: StyleIsolation.PageShared,
|
|
398
455
|
})
|
|
399
|
-
codeSpace.addCompiledTemplate(
|
|
456
|
+
codeSpace.addCompiledTemplate(
|
|
457
|
+
'path/to/comp',
|
|
458
|
+
tmpl(`
|
|
400
459
|
<div class="abc">
|
|
401
460
|
<child />
|
|
402
461
|
</div>
|
|
403
|
-
`)
|
|
462
|
+
`),
|
|
463
|
+
)
|
|
404
464
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
405
465
|
Component().register()
|
|
406
466
|
})
|
|
@@ -420,9 +480,12 @@ describe('define', () => {
|
|
|
420
480
|
component: true,
|
|
421
481
|
styleIsolation: StyleIsolation.ApplyShared,
|
|
422
482
|
})
|
|
423
|
-
codeSpace.addCompiledTemplate(
|
|
483
|
+
codeSpace.addCompiledTemplate(
|
|
484
|
+
'child/comp',
|
|
485
|
+
tmpl(`
|
|
424
486
|
<div class="def"></div>
|
|
425
|
-
`)
|
|
487
|
+
`),
|
|
488
|
+
)
|
|
426
489
|
codeSpace.componentEnv('child/comp', ({ Component }) => {
|
|
427
490
|
Component()
|
|
428
491
|
.options({
|
|
@@ -438,11 +501,14 @@ describe('define', () => {
|
|
|
438
501
|
},
|
|
439
502
|
styleIsolation: StyleIsolation.PageApplyShared,
|
|
440
503
|
})
|
|
441
|
-
codeSpace.addCompiledTemplate(
|
|
504
|
+
codeSpace.addCompiledTemplate(
|
|
505
|
+
'path/to/comp',
|
|
506
|
+
tmpl(`
|
|
442
507
|
<div class="abc">
|
|
443
508
|
<child />
|
|
444
509
|
</div>
|
|
445
|
-
`)
|
|
510
|
+
`),
|
|
511
|
+
)
|
|
446
512
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
447
513
|
Component().register()
|
|
448
514
|
})
|
|
@@ -450,7 +516,9 @@ describe('define', () => {
|
|
|
450
516
|
const ab = env.associateBackend()
|
|
451
517
|
ab.registerStyleSheetContent('empty-style-sheet', '')
|
|
452
518
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
453
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
519
|
+
expect(domHtml(root.getComponent())).toBe(
|
|
520
|
+
'<div class="abc comp--abc"><div class="def child-comp--def"></div></div>',
|
|
521
|
+
)
|
|
454
522
|
})
|
|
455
523
|
|
|
456
524
|
test('options styleIsolation isolated', () => {
|
|
@@ -462,9 +530,12 @@ describe('define', () => {
|
|
|
462
530
|
component: true,
|
|
463
531
|
styleIsolation: StyleIsolation.Isolated,
|
|
464
532
|
})
|
|
465
|
-
codeSpace.addCompiledTemplate(
|
|
533
|
+
codeSpace.addCompiledTemplate(
|
|
534
|
+
'child/comp',
|
|
535
|
+
tmpl(`
|
|
466
536
|
<div class="def"></div>
|
|
467
|
-
`)
|
|
537
|
+
`),
|
|
538
|
+
)
|
|
468
539
|
codeSpace.componentEnv('child/comp', ({ Component }) => {
|
|
469
540
|
Component()
|
|
470
541
|
.options({
|
|
@@ -480,11 +551,14 @@ describe('define', () => {
|
|
|
480
551
|
},
|
|
481
552
|
styleIsolation: StyleIsolation.PageIsolated,
|
|
482
553
|
})
|
|
483
|
-
codeSpace.addCompiledTemplate(
|
|
554
|
+
codeSpace.addCompiledTemplate(
|
|
555
|
+
'path/to/comp',
|
|
556
|
+
tmpl(`
|
|
484
557
|
<div class="abc">
|
|
485
558
|
<child />
|
|
486
559
|
</div>
|
|
487
|
-
`)
|
|
560
|
+
`),
|
|
561
|
+
)
|
|
488
562
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
489
563
|
Component().register()
|
|
490
564
|
})
|
|
@@ -492,7 +566,9 @@ describe('define', () => {
|
|
|
492
566
|
const ab = env.associateBackend()
|
|
493
567
|
ab.registerStyleSheetContent('empty-style-sheet', '')
|
|
494
568
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
495
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
569
|
+
expect(domHtml(root.getComponent())).toBe(
|
|
570
|
+
'<div class="comp--abc"><div class="child-comp--def"></div></div>',
|
|
571
|
+
)
|
|
496
572
|
})
|
|
497
573
|
|
|
498
574
|
test('options dataDeepCopy', () => {
|
|
@@ -529,9 +605,12 @@ describe('define', () => {
|
|
|
529
605
|
codeSpace.addComponentStaticConfig('child/comp', {
|
|
530
606
|
component: true,
|
|
531
607
|
})
|
|
532
|
-
codeSpace.addCompiledTemplate(
|
|
608
|
+
codeSpace.addCompiledTemplate(
|
|
609
|
+
'child/comp',
|
|
610
|
+
tmpl(`
|
|
533
611
|
<div class="def"></div>
|
|
534
|
-
`)
|
|
612
|
+
`),
|
|
613
|
+
)
|
|
535
614
|
// eslint-disable-next-line arrow-body-style
|
|
536
615
|
const childDef = codeSpace.componentEnv('child/comp', ({ Component }) => {
|
|
537
616
|
return Component()
|
|
@@ -550,9 +629,12 @@ describe('define', () => {
|
|
|
550
629
|
},
|
|
551
630
|
styleIsolation: StyleIsolation.PageIsolated,
|
|
552
631
|
})
|
|
553
|
-
codeSpace.addCompiledTemplate(
|
|
632
|
+
codeSpace.addCompiledTemplate(
|
|
633
|
+
'path/to/comp',
|
|
634
|
+
tmpl(`
|
|
554
635
|
<child id="c" p="{{a}}" />
|
|
555
|
-
`)
|
|
636
|
+
`),
|
|
637
|
+
)
|
|
556
638
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
557
639
|
Component()
|
|
558
640
|
.options({
|
|
@@ -584,17 +666,22 @@ describe('define', () => {
|
|
|
584
666
|
const env = new MiniProgramEnv()
|
|
585
667
|
const codeSpace = env.createCodeSpace('', true)
|
|
586
668
|
|
|
587
|
-
codeSpace.addCompiledTemplate(
|
|
669
|
+
codeSpace.addCompiledTemplate(
|
|
670
|
+
'path/to/comp',
|
|
671
|
+
tmpl(`
|
|
588
672
|
<div>{{a}}-{{b}}</div>
|
|
589
|
-
`)
|
|
673
|
+
`),
|
|
674
|
+
)
|
|
590
675
|
|
|
591
|
-
const beh = codeSpace
|
|
676
|
+
const beh = codeSpace
|
|
677
|
+
.behavior()
|
|
592
678
|
.data(() => ({
|
|
593
679
|
a: 123,
|
|
594
680
|
}))
|
|
595
681
|
.register()
|
|
596
682
|
|
|
597
|
-
const filterBeh = codeSpace
|
|
683
|
+
const filterBeh = codeSpace
|
|
684
|
+
.behavior()
|
|
598
685
|
.behavior(beh)
|
|
599
686
|
.definition({
|
|
600
687
|
definitionFilter: (def: types.GeneralComponentDefinition) => {
|
|
@@ -604,7 +691,8 @@ describe('define', () => {
|
|
|
604
691
|
})
|
|
605
692
|
.register()
|
|
606
693
|
|
|
607
|
-
codeSpace
|
|
694
|
+
codeSpace
|
|
695
|
+
.component('path/to/comp')
|
|
608
696
|
.definition({
|
|
609
697
|
behaviors: [filterBeh],
|
|
610
698
|
})
|
|
@@ -619,17 +707,22 @@ describe('define', () => {
|
|
|
619
707
|
const env = new MiniProgramEnv()
|
|
620
708
|
const codeSpace = env.createCodeSpace('', true)
|
|
621
709
|
|
|
622
|
-
codeSpace.addCompiledTemplate(
|
|
710
|
+
codeSpace.addCompiledTemplate(
|
|
711
|
+
'path/to/comp',
|
|
712
|
+
tmpl(`
|
|
623
713
|
<div>{{a}}-{{b}}</div>
|
|
624
|
-
`)
|
|
714
|
+
`),
|
|
715
|
+
)
|
|
625
716
|
|
|
626
|
-
const beh = codeSpace
|
|
717
|
+
const beh = codeSpace
|
|
718
|
+
.behavior()
|
|
627
719
|
.data(() => ({
|
|
628
720
|
a: 123,
|
|
629
721
|
}))
|
|
630
722
|
.register()
|
|
631
723
|
|
|
632
|
-
codeSpace
|
|
724
|
+
codeSpace
|
|
725
|
+
.component('path/to/comp')
|
|
633
726
|
.behavior(beh)
|
|
634
727
|
.data(() => ({
|
|
635
728
|
b: 456,
|
|
@@ -645,13 +738,17 @@ describe('define', () => {
|
|
|
645
738
|
const env = new MiniProgramEnv()
|
|
646
739
|
const codeSpace = env.createCodeSpace('', true)
|
|
647
740
|
|
|
648
|
-
codeSpace.addCompiledTemplate(
|
|
741
|
+
codeSpace.addCompiledTemplate(
|
|
742
|
+
'path/to/comp',
|
|
743
|
+
tmpl(`
|
|
649
744
|
<div>{{a}}-{{b}}</div>
|
|
650
|
-
`)
|
|
745
|
+
`),
|
|
746
|
+
)
|
|
651
747
|
|
|
652
748
|
type TAdd = { data: <T>(this: T) => T }
|
|
653
749
|
type TRemove = 'data' | 'property'
|
|
654
|
-
const beh = codeSpace
|
|
750
|
+
const beh = codeSpace
|
|
751
|
+
.behavior()
|
|
655
752
|
.chainingFilter<TAdd, TRemove>((chain) => {
|
|
656
753
|
const oldData = chain.data.bind(chain)
|
|
657
754
|
const newData = function () {
|
|
@@ -666,7 +763,8 @@ describe('define', () => {
|
|
|
666
763
|
})
|
|
667
764
|
.register()
|
|
668
765
|
|
|
669
|
-
codeSpace
|
|
766
|
+
codeSpace
|
|
767
|
+
.component('path/to/comp')
|
|
670
768
|
.data(() => ({
|
|
671
769
|
b: 456,
|
|
672
770
|
}))
|
|
@@ -686,9 +784,12 @@ describe('define', () => {
|
|
|
686
784
|
codeSpace.addComponentStaticConfig('child/comp', {
|
|
687
785
|
component: true,
|
|
688
786
|
})
|
|
689
|
-
codeSpace.addCompiledTemplate(
|
|
787
|
+
codeSpace.addCompiledTemplate(
|
|
788
|
+
'child/comp',
|
|
789
|
+
tmpl(`
|
|
690
790
|
<div class="a-class"></div>
|
|
691
|
-
`)
|
|
791
|
+
`),
|
|
792
|
+
)
|
|
692
793
|
codeSpace.componentEnv('child/comp', ({ Component }) => {
|
|
693
794
|
Component()
|
|
694
795
|
.options({
|
|
@@ -703,11 +804,14 @@ describe('define', () => {
|
|
|
703
804
|
child: '/child/comp',
|
|
704
805
|
},
|
|
705
806
|
})
|
|
706
|
-
codeSpace.addCompiledTemplate(
|
|
807
|
+
codeSpace.addCompiledTemplate(
|
|
808
|
+
'path/to/comp',
|
|
809
|
+
tmpl(`
|
|
707
810
|
<div class="abc">
|
|
708
811
|
<child a-class="def" />
|
|
709
812
|
</div>
|
|
710
|
-
`)
|
|
813
|
+
`),
|
|
814
|
+
)
|
|
711
815
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
712
816
|
Component().register()
|
|
713
817
|
})
|
|
@@ -746,9 +850,12 @@ describe('define', () => {
|
|
|
746
850
|
child: '/child/comp',
|
|
747
851
|
},
|
|
748
852
|
})
|
|
749
|
-
codeSpace.addCompiledTemplate(
|
|
853
|
+
codeSpace.addCompiledTemplate(
|
|
854
|
+
'path/to/comp',
|
|
855
|
+
tmpl(`
|
|
750
856
|
<child id="c" />
|
|
751
|
-
`)
|
|
857
|
+
`),
|
|
858
|
+
)
|
|
752
859
|
// eslint-disable-next-line arrow-body-style
|
|
753
860
|
const parentType = codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
754
861
|
return Component()
|
|
@@ -777,9 +884,12 @@ describe('define', () => {
|
|
|
777
884
|
codeSpace.addComponentStaticConfig('child/comp', {
|
|
778
885
|
component: true,
|
|
779
886
|
})
|
|
780
|
-
codeSpace.addCompiledTemplate(
|
|
887
|
+
codeSpace.addCompiledTemplate(
|
|
888
|
+
'child/comp',
|
|
889
|
+
tmpl(`
|
|
781
890
|
<span>{{aa}}</span>
|
|
782
|
-
`)
|
|
891
|
+
`),
|
|
892
|
+
)
|
|
783
893
|
codeSpace.componentEnv('child/comp', ({ Component }) => {
|
|
784
894
|
Component()
|
|
785
895
|
.options({
|
|
@@ -802,9 +912,12 @@ describe('define', () => {
|
|
|
802
912
|
child: '/child/comp',
|
|
803
913
|
},
|
|
804
914
|
})
|
|
805
|
-
codeSpace.addCompiledTemplate(
|
|
915
|
+
codeSpace.addCompiledTemplate(
|
|
916
|
+
'path/to/comp',
|
|
917
|
+
tmpl(`
|
|
806
918
|
<child a="{{bb}}" />
|
|
807
|
-
`)
|
|
919
|
+
`),
|
|
920
|
+
)
|
|
808
921
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
809
922
|
Component()
|
|
810
923
|
.data(() => ({
|
|
@@ -836,9 +949,12 @@ describe('define', () => {
|
|
|
836
949
|
codeSpace.addComponentStaticConfig('child/comp', {
|
|
837
950
|
component: true,
|
|
838
951
|
})
|
|
839
|
-
codeSpace.addCompiledTemplate(
|
|
952
|
+
codeSpace.addCompiledTemplate(
|
|
953
|
+
'child/comp',
|
|
954
|
+
tmpl(`
|
|
840
955
|
<span>{{a}}-{{b}}</span>
|
|
841
|
-
`)
|
|
956
|
+
`),
|
|
957
|
+
)
|
|
842
958
|
codeSpace.componentEnv('child/comp', ({ Component }) => {
|
|
843
959
|
Component()
|
|
844
960
|
.options({
|
|
@@ -861,9 +977,12 @@ describe('define', () => {
|
|
|
861
977
|
child: '/child/comp',
|
|
862
978
|
},
|
|
863
979
|
})
|
|
864
|
-
codeSpace.addCompiledTemplate(
|
|
980
|
+
codeSpace.addCompiledTemplate(
|
|
981
|
+
'path/to/comp',
|
|
982
|
+
tmpl(`
|
|
865
983
|
<child a="{{a}}" />
|
|
866
|
-
`)
|
|
984
|
+
`),
|
|
985
|
+
)
|
|
867
986
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
868
987
|
Component()
|
|
869
988
|
.data(() => ({
|
|
@@ -889,9 +1008,12 @@ describe('define', () => {
|
|
|
889
1008
|
codeSpace.addComponentStaticConfig('child/list', {
|
|
890
1009
|
component: true,
|
|
891
1010
|
})
|
|
892
|
-
codeSpace.addCompiledTemplate(
|
|
1011
|
+
codeSpace.addCompiledTemplate(
|
|
1012
|
+
'child/list',
|
|
1013
|
+
tmpl(`
|
|
893
1014
|
<div>{{count}}</div><slot />
|
|
894
|
-
`)
|
|
1015
|
+
`),
|
|
1016
|
+
)
|
|
895
1017
|
// eslint-disable-next-line arrow-body-style
|
|
896
1018
|
const listDef = codeSpace.componentEnv('child/list', ({ Component }) => {
|
|
897
1019
|
return Component()
|
|
@@ -935,12 +1057,15 @@ describe('define', () => {
|
|
|
935
1057
|
item: '/child/item',
|
|
936
1058
|
},
|
|
937
1059
|
})
|
|
938
|
-
codeSpace.addCompiledTemplate(
|
|
1060
|
+
codeSpace.addCompiledTemplate(
|
|
1061
|
+
'path/to/comp',
|
|
1062
|
+
tmpl(`
|
|
939
1063
|
<list>
|
|
940
1064
|
<item />
|
|
941
1065
|
<item />
|
|
942
1066
|
</list>
|
|
943
|
-
`)
|
|
1067
|
+
`),
|
|
1068
|
+
)
|
|
944
1069
|
codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
945
1070
|
Component().register()
|
|
946
1071
|
})
|