Skip to content

Commit a71eb72

Browse files
author
boquanfu
committed
fix: behavior typing
1 parent e0db1ba commit a71eb72

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "miniprogram-chaining-api-polyfill",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Chaining API Polyfill for WeChat MiniProgram without glass-easel",
55
"main": "dist/index.js",
66
"types": "src/index.ts",

src/behavior.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface IBehaviorWithPolyfill {
3535
TBehavior,
3636
TCustomInstanceProperty
3737
>,
38-
): string
38+
): WechatMiniprogram.Behavior.BehaviorIdentifier<TData, TProperty, TMethod, TBehavior>
3939
trait<TIn extends { [key: string]: any }>(): TraitBehavior<TIn, TIn>
4040
trait<TIn extends { [key: string]: any }, TOut extends { [key: string]: any }>(
4141
trans: (impl: TIn) => TOut,

test/chaining.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,34 @@ describe('chaining calls', () => {
3838
const beh2 = Behavior().behavior(beh).register()
3939
Component()
4040
.behavior(beh2)
41+
.property('propA', String)
42+
.staticData({
43+
text: 'abc',
44+
})
45+
.lifetime('attached', function () {
46+
this.setData({
47+
text: 'ghi',
48+
})
49+
})
50+
.register()
51+
})
52+
expect(innerHTML(component)).toBe('<div>ghidef</div>')
53+
})
54+
55+
test('`.behavior (with definition API)`', () => {
56+
const component = renderComponent(undefined, `<div>{{ text }}{{ text2 }}</div>`, () => {
57+
const beh = Behavior({
58+
data: { text2: 'abc' },
59+
properties: { propB: String },
60+
lifetimes: {
61+
attached() {
62+
this.setData({ text: 'def', text2: 'def' })
63+
},
64+
},
65+
})
66+
Component()
67+
.behavior(beh)
68+
.property('propA', String)
4169
.staticData({
4270
text: 'abc',
4371
})

0 commit comments

Comments
 (0)