glass-easel-miniprogram-adapter 0.7.0 → 0.8.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.d.ts +12 -3
- package/dist/glass_easel_miniprogram_adapter.es.js +1 -1
- package/dist/glass_easel_miniprogram_adapter.es.js.map +1 -1
- package/dist/glass_easel_miniprogram_adapter.js +1 -1
- package/dist/glass_easel_miniprogram_adapter.js.map +1 -1
- package/package.json +4 -4
- package/src/builder/base_behavior_builder.ts +20 -2
- package/src/builder/behavior_builder.ts +7 -1
- package/src/builder/component_builder.ts +7 -1
- package/tests/env.test.ts +1 -1
- package/tests/selector.test.ts +10 -4
- package/tests/space.test.ts +12 -9
- package/tests/trait_behavior.test.ts +1 -1
|
@@ -23,6 +23,7 @@ type MethodList = typeUtils.MethodList
|
|
|
23
23
|
type ChainingFilterType = typeUtils.ChainingFilterType
|
|
24
24
|
type ComponentMethod = typeUtils.ComponentMethod
|
|
25
25
|
type TaggedMethod<Fn extends ComponentMethod> = typeUtils.TaggedMethod<Fn>
|
|
26
|
+
type UnTaggedMethod<M extends TaggedMethod<any>> = typeUtils.UnTaggedMethod<M>
|
|
26
27
|
|
|
27
28
|
export class BaseBehaviorBuilder<
|
|
28
29
|
TPrevData extends DataList = Empty,
|
|
@@ -260,7 +261,12 @@ export class BaseBehaviorBuilder<
|
|
|
260
261
|
TPrevData,
|
|
261
262
|
TData,
|
|
262
263
|
TProperty,
|
|
263
|
-
TMethod
|
|
264
|
+
TMethod &
|
|
265
|
+
(TExport extends void
|
|
266
|
+
? Empty
|
|
267
|
+
: {
|
|
268
|
+
[K in keyof TExport]: UnTaggedMethod<TExport[K]>
|
|
269
|
+
}),
|
|
264
270
|
TChainingFilter,
|
|
265
271
|
TPendingChainingFilter,
|
|
266
272
|
TComponentExport,
|
|
@@ -316,7 +322,7 @@ export class BaseBehaviorBuilder<
|
|
|
316
322
|
TExtraThisFields
|
|
317
323
|
>
|
|
318
324
|
|
|
319
|
-
|
|
325
|
+
const exported = func.call(methodCaller, {
|
|
320
326
|
self: methodCaller,
|
|
321
327
|
data,
|
|
322
328
|
setData: (newData, callback) => {
|
|
@@ -335,6 +341,18 @@ export class BaseBehaviorBuilder<
|
|
|
335
341
|
method,
|
|
336
342
|
listener,
|
|
337
343
|
})
|
|
344
|
+
|
|
345
|
+
if (exported) {
|
|
346
|
+
const exportedKeys = Object.keys(exported)
|
|
347
|
+
for (let j = 0; j < exportedKeys.length; j += 1) {
|
|
348
|
+
const exportedKey = exportedKeys[j]!
|
|
349
|
+
const exportItem: unknown = exported[exportedKey]
|
|
350
|
+
if (glassEasel.Component.isTaggedMethod(exportItem)) {
|
|
351
|
+
;(methodCaller as { [key: string]: unknown })[exportedKey] = exportItem
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return exported
|
|
338
356
|
})
|
|
339
357
|
return this as any
|
|
340
358
|
}
|
|
@@ -17,6 +17,7 @@ type MethodList = typeUtils.MethodList
|
|
|
17
17
|
type ChainingFilterType = typeUtils.ChainingFilterType
|
|
18
18
|
type ComponentMethod = typeUtils.ComponentMethod
|
|
19
19
|
type TaggedMethod<Fn extends ComponentMethod> = typeUtils.TaggedMethod<Fn>
|
|
20
|
+
type UnTaggedMethod<M extends TaggedMethod<any>> = typeUtils.UnTaggedMethod<M>
|
|
20
21
|
type ChainingFilterFunc<
|
|
21
22
|
TAddedFields extends { [key: string]: any },
|
|
22
23
|
TRemovedFields extends string = never,
|
|
@@ -217,7 +218,12 @@ export class BehaviorBuilder<
|
|
|
217
218
|
TPrevData,
|
|
218
219
|
TData,
|
|
219
220
|
TProperty,
|
|
220
|
-
TMethod
|
|
221
|
+
TMethod &
|
|
222
|
+
(TExport extends void
|
|
223
|
+
? Empty
|
|
224
|
+
: {
|
|
225
|
+
[K in keyof TExport]: UnTaggedMethod<TExport[K]>
|
|
226
|
+
}),
|
|
221
227
|
TChainingFilter,
|
|
222
228
|
TPendingChainingFilter,
|
|
223
229
|
TComponentExport,
|
|
@@ -24,6 +24,7 @@ type MethodList = typeUtils.MethodList
|
|
|
24
24
|
type ChainingFilterType = typeUtils.ChainingFilterType
|
|
25
25
|
type ComponentMethod = typeUtils.ComponentMethod
|
|
26
26
|
type TaggedMethod<Fn extends ComponentMethod> = typeUtils.TaggedMethod<Fn>
|
|
27
|
+
type UnTaggedMethod<M extends TaggedMethod<any>> = typeUtils.UnTaggedMethod<M>
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* A direct way to create a component
|
|
@@ -241,7 +242,12 @@ export class ComponentBuilder<
|
|
|
241
242
|
TPrevData,
|
|
242
243
|
TData,
|
|
243
244
|
TProperty,
|
|
244
|
-
TMethod
|
|
245
|
+
TMethod &
|
|
246
|
+
(TExport extends void
|
|
247
|
+
? Empty
|
|
248
|
+
: {
|
|
249
|
+
[K in keyof TExport]: UnTaggedMethod<TExport[K]>
|
|
250
|
+
}),
|
|
245
251
|
TChainingFilter,
|
|
246
252
|
TPendingChainingFilter,
|
|
247
253
|
TComponentExport,
|
package/tests/env.test.ts
CHANGED
|
@@ -135,7 +135,7 @@ describe('env', () => {
|
|
|
135
135
|
const ab = env.associateBackend(backend)
|
|
136
136
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
137
137
|
expect(domHtml(root.getComponent())).toBe(
|
|
138
|
-
'<c-a>A</c-a><c-aa>A</c-aa><i-a></i-a><i-b></i-b><c-b>B</c-b>',
|
|
138
|
+
'<c-a is="inner-comp-1">A</c-a><c-aa is="inner-comp-1">A</c-aa><i-a></i-a><i-b></i-b><c-b is="inner-comp-2">B</c-b>',
|
|
139
139
|
)
|
|
140
140
|
})
|
|
141
141
|
})
|
package/tests/selector.test.ts
CHANGED
|
@@ -72,7 +72,9 @@ describe('selector query', () => {
|
|
|
72
72
|
const ab = env.associateBackend()
|
|
73
73
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
74
74
|
glassEasel.Element.pretendAttached(root.getComponent())
|
|
75
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
75
|
+
expect(domHtml(root.getComponent())).toBe(
|
|
76
|
+
'<div><child is="child/comp">456</child><child is="child/comp">789</child></div>',
|
|
77
|
+
)
|
|
76
78
|
})
|
|
77
79
|
|
|
78
80
|
test('select single component (with custom export)', () => {
|
|
@@ -159,7 +161,9 @@ describe('selector query', () => {
|
|
|
159
161
|
const ab = env.associateBackend()
|
|
160
162
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
161
163
|
glassEasel.Element.pretendAttached(root.getComponent())
|
|
162
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
164
|
+
expect(domHtml(root.getComponent())).toBe(
|
|
165
|
+
'<div><child1 is="child1/comp">456</child1><child2 is="child2/comp">789</child2></div>',
|
|
166
|
+
)
|
|
163
167
|
})
|
|
164
168
|
|
|
165
169
|
test('select single component (with custom export on behavior)', () => {
|
|
@@ -251,7 +255,9 @@ describe('selector query', () => {
|
|
|
251
255
|
const ab = env.associateBackend()
|
|
252
256
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
253
257
|
glassEasel.Element.pretendAttached(root.getComponent())
|
|
254
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
258
|
+
expect(domHtml(root.getComponent())).toBe(
|
|
259
|
+
'<div><child1 is="child1/comp">456</child1><child2 is="child2/comp">789</child2></div>',
|
|
260
|
+
)
|
|
255
261
|
})
|
|
256
262
|
|
|
257
263
|
test('select all components', () => {
|
|
@@ -316,7 +322,7 @@ describe('selector query', () => {
|
|
|
316
322
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
317
323
|
glassEasel.Element.pretendAttached(root.getComponent())
|
|
318
324
|
expect(domHtml(root.getComponent())).toBe(
|
|
319
|
-
'<div><child class="c">0</child><child class="c">1</child><child-b class="c">2</child-b></div>',
|
|
325
|
+
'<div><child is="child/comp" class="c">0</child><child is="child/comp" class="c">1</child><child-b is="child/comp2" class="c">2</child-b></div>',
|
|
320
326
|
)
|
|
321
327
|
})
|
|
322
328
|
|
package/tests/space.test.ts
CHANGED
|
@@ -249,7 +249,9 @@ describe('define', () => {
|
|
|
249
249
|
|
|
250
250
|
const ab = env.associateBackend()
|
|
251
251
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
252
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
252
|
+
expect(domHtml(root.getComponent())).toBe(
|
|
253
|
+
'<a is="comp/a"><c is="comp/b"><span>B</span></c></a>',
|
|
254
|
+
)
|
|
253
255
|
})
|
|
254
256
|
|
|
255
257
|
test('options placeholder', () => {
|
|
@@ -290,7 +292,7 @@ describe('define', () => {
|
|
|
290
292
|
|
|
291
293
|
const ab = env.associateBackend()
|
|
292
294
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
293
|
-
expect(domHtml(root.getComponent())).toBe('<a><div>A</div></a>')
|
|
295
|
+
expect(domHtml(root.getComponent())).toBe('<a is="comp/a"><div>A</div></a>')
|
|
294
296
|
|
|
295
297
|
codeSpace.addComponentStaticConfig('comp/b', {
|
|
296
298
|
component: true,
|
|
@@ -305,7 +307,7 @@ describe('define', () => {
|
|
|
305
307
|
Component().register()
|
|
306
308
|
})
|
|
307
309
|
|
|
308
|
-
expect(domHtml(root.getComponent())).toBe('<a><span>B</span></a>')
|
|
310
|
+
expect(domHtml(root.getComponent())).toBe('<a is="comp/b"><span>B</span></a>')
|
|
309
311
|
})
|
|
310
312
|
|
|
311
313
|
test('options pureDataPattern (js)', () => {
|
|
@@ -853,15 +855,14 @@ describe('define', () => {
|
|
|
853
855
|
// eslint-disable-next-line arrow-body-style
|
|
854
856
|
const parentType = codeSpace.componentEnv('path/to/comp', ({ Component }) => {
|
|
855
857
|
return Component()
|
|
856
|
-
.methods({
|
|
857
|
-
parentFn() {
|
|
858
|
-
return 456
|
|
859
|
-
},
|
|
860
|
-
})
|
|
861
858
|
.lifetime('attached', function () {
|
|
862
859
|
expect(this.selectComponent('#c', childType)!.childFn()).toBe(123)
|
|
863
860
|
callOrder.push(2)
|
|
864
861
|
})
|
|
862
|
+
.init(({ method }) => {
|
|
863
|
+
const parentFn = method(() => 456)
|
|
864
|
+
return { parentFn }
|
|
865
|
+
})
|
|
865
866
|
.register()
|
|
866
867
|
})
|
|
867
868
|
|
|
@@ -1067,7 +1068,9 @@ describe('define', () => {
|
|
|
1067
1068
|
const ab = env.associateBackend()
|
|
1068
1069
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
1069
1070
|
glassEasel.Element.pretendAttached(root.getComponent())
|
|
1070
|
-
expect(domHtml(root.getComponent())).toBe(
|
|
1071
|
+
expect(domHtml(root.getComponent())).toBe(
|
|
1072
|
+
'<list is="child/list"><div>2</div><item is="child/item"></item><item is="child/item"></item></list>',
|
|
1073
|
+
)
|
|
1071
1074
|
})
|
|
1072
1075
|
|
|
1073
1076
|
test('chaining extraThisFieldsType', () => {
|
|
@@ -138,7 +138,7 @@ describe('trait behavior', () => {
|
|
|
138
138
|
const root = ab.createRoot('body', codeSpace, 'path/to/comp')
|
|
139
139
|
glassEasel.Element.pretendAttached(root.getComponent())
|
|
140
140
|
expect(domHtml(root.getComponent())).toBe(
|
|
141
|
-
'<list><div>2</div><item>2</item><item>3</item></list>',
|
|
141
|
+
'<list is="child/list"><div>2</div><item is="child/item">2</item><item is="child/item">3</item></list>',
|
|
142
142
|
)
|
|
143
143
|
})
|
|
144
144
|
})
|