Skip to content

Commit

Permalink
Merge pull request #190 from wechat-miniprogram/fix-adapter-chaining-…
Browse files Browse the repository at this point in the history
…filter

fix(miniprogram-adapter): chaining filter should work on the adapter chain
  • Loading branch information
LastLeaf authored Aug 15, 2024
2 parents e2ddc2e + 18f73e2 commit b9544cb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions glass-easel-miniprogram-adapter/src/behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class Behavior<
/** @internal */
_$: glassEasel.GeneralBehavior
/** @internal */
_$chainingFilter?: typeUtils.ChainingFilterFunc<any, any>
/** @internal */
_$bindedDefinitionFilter?: (target: GeneralComponentDefinition) => void
/** @internal */
_$export?: (source: GeneralComponent | null) => TComponentExport
Expand All @@ -41,9 +43,11 @@ export class Behavior<
inner: glassEasel.Behavior<TData, TProperty, TMethod, TChainingFilter, TExtraThisFields>,
parents: GeneralBehavior[],
definitionFilter: DefinitionFilter | undefined,
chainingFilter: typeUtils.ChainingFilterFunc<any, any> | undefined,
componentExport: ((source: GeneralComponent | null) => TComponentExport) | undefined,
) {
this._$ = inner as glassEasel.GeneralBehavior
this._$chainingFilter = chainingFilter
this._$export = componentExport

// processing definition filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class BehaviorBuilder<
TExtraThisFields
> {
private _$definitionFilter: DefinitionFilter | undefined
private _$chainingFilter?: ChainingFilterFunc<any, any>

/** @internal */
static create(codeSpace: CodeSpace): BehaviorBuilder {
Expand Down Expand Up @@ -74,7 +75,7 @@ export class BehaviorBuilder<
>,
TChainingFilter
> {
this._$.chainingFilter(func as any)
this._$chainingFilter = func
return this as any
}

Expand Down Expand Up @@ -103,6 +104,9 @@ export class BehaviorBuilder<
this._$parents.push(behavior as GeneralBehavior)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this._$ = this._$.behavior(behavior._$)
if (behavior._$chainingFilter) {
return behavior._$chainingFilter(this as any)
}
return this as any
}

Expand Down Expand Up @@ -284,6 +288,7 @@ export class BehaviorBuilder<
this._$.registerBehavior(),
this._$parents,
this._$definitionFilter,
this._$chainingFilter,
this._$export,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export class ComponentBuilder<
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this._$export = behavior._$export as any
}
if (behavior._$chainingFilter) {
return behavior._$chainingFilter(this as any)
}
return this as any
}

Expand Down
2 changes: 1 addition & 1 deletion glass-easel-miniprogram-adapter/tests/space.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ describe('define', () => {
.chainingFilter<TAdd, TRemove>((chain) => {
const oldData = chain.data.bind(chain)
const newData = function () {
oldData(() => ({
return oldData(() => ({
a: 123,
}))
}
Expand Down

0 comments on commit b9544cb

Please sign in to comment.