Skip to content

Commit

Permalink
fix: add controller (and other properties) to datacontext extension
Browse files Browse the repository at this point in the history
  • Loading branch information
npenin committed Sep 8, 2024
1 parent 92b7ff2 commit a1d9b88
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/client/src/behaviors/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export type IDataContext<TController extends Partial<Disposable> = Partial<Dispo

export class DataContext implements Composer<IDataContext>
{
static propagateProperties: string[] = ['controller'];

static define(item: HTMLElement, context: Record<string, unknown>): void
{
item.setAttribute('data-context', '');
Expand All @@ -23,6 +25,8 @@ export class DataContext implements Composer<IDataContext>
return sourceContext.pipe(new CallExpression(new ConstantExpression(Object), new ConstantExpression('assign'), [new NewExpression<{ context: any, controller: Partial<Disposable> }>(
...Object.entries(options).filter(e => e[0] !== 'context').map(e =>
new MemberExpression<any, any, any>(new ConstantExpression(e[1]), new ConstantExpression(e[0]), false)),
...DataContext.propagateProperties.map(e =>
new MemberExpression<any, any, any>(new MemberExpression(null, new ConstantExpression(e), false), new ConstantExpression(e), false)),
new MemberExpression(Parser.parameterLess.parse(newContextPath || 'context') as any, new ConstantExpression('context'), false),
), new MemberExpression(null, null, false)]));
}
Expand Down

0 comments on commit a1d9b88

Please sign in to comment.