LuccaSA/lucca-front

Authorize custom dialog data model without data property on dialog component

Opened this issue · 0 comments

Problem

My dialog data model :

export interface MyDialogData {
  customParam1: number
  customParam2: boolean
}

My component :

@Component({
  ...,
  providers: [MyDialogStore],
})
export class MyDialogComponent {
  readonly store = inject(MyDialogStore)
  // Useless inject, only use for typing data on LuDIalogService.open call 
  readonly data = injectDialogData<MyDialogData>()
}

My store :

interface State {
  customParam1: MyDialogData['customParam1']
  customParam2: MyDialogData['customParam2']
}

export const MyDialogStore = signalStore(
  withState<State>(
    ({ customParam1, customParam2 } = injectDialogData<MyDialogData>()) => ({
        customParam1,
        customParam2
      };
    },
  ),
);

Dialog open call :

inject(LuDialogService).open({
  content: MyDialogComponent,
  data: {
    customParam1: 10,
    customParam2: true
  },
})

Proposition

Dialog open call :

// Explicit dialog data model with second type parameter
inject(LuDialogService).open<MyDialogComponent, MyDialogData>({
  content: MyDialogComponent,
  data: {
    customParam1: 10,
    customParam2: true
  },
})

My component :

@Component({
  ...,
  providers: [MyDialogStore],
})
export class MyDialogComponent{
  readonly store = inject(MyDialogStore)
  // No useless inject
}