Skip to content

Commit

Permalink
feat: bye bye actions (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinderoubaix authored Oct 18, 2024
1 parent c718381 commit 59853ba
Show file tree
Hide file tree
Showing 30 changed files with 32 additions and 72 deletions.
2 changes: 1 addition & 1 deletion angular/bootstrap/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const widgetFactories: {
provideWidgetsConfig: (adaptParentConfig?: AdaptParentConfig) => FactoryProvider;
injectWidgetConfig: <N extends keyof BootstrapWidgetsConfig>(widgetName: N) => ReadableSignal<Partial<WidgetsConfig[N]> | undefined>;
injectWidgetsConfig: InjectWidgetsConfig;
callWidgetFactory: <W extends Widget<object, object, object, object, object>>({
callWidgetFactory: <W extends Widget<object, object, object, object>>({
factory,
widgetName,
defaultConfig,
Expand Down
19 changes: 2 additions & 17 deletions angular/headless/src/utils/widget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ describe('callWidgetFactoryWithConfig', () => {
{onMyAction: () => void; onCounterChange: (value: number) => void; myValue: string},
{derivedValue: string; counter: number},
{myApiFn: () => void; incrementCounter: () => void},
{myAction: () => void},
{myDirective: Directive}
>;

const factory: WidgetFactory<MyWidget> = createZoneCheckFn('factory', (propsConfig) => {
const [{onMyAction$, onCounterChange$, myValue$}, patch] = writablesForProps(
const [{onCounterChange$, myValue$}, patch] = writablesForProps(
{
onMyAction: noop,
onCounterChange: noop,
Expand All @@ -65,11 +64,6 @@ describe('callWidgetFactoryWithConfig', () => {
onCounterChange$()(value);
}),
},
actions: {
myAction: createZoneCheckFn('myAction', () => {
onMyAction$()();
}),
},
directives: {
myDirective: createZoneCheckFn('myDirective', () => ({
update: createZoneCheckFn('myDirectiveUpdate', noop),
Expand Down Expand Up @@ -103,8 +97,6 @@ describe('callWidgetFactoryWithConfig', () => {
onMyAction: () => this.myAction.emit(),
},
});

onClick = createZoneCheckFn('onClick', () => this._widget.actions.myAction());
}

const ngZone = TestBed.inject(NgZone);
Expand Down Expand Up @@ -175,12 +167,6 @@ describe('callWidgetFactoryWithConfig', () => {
'after ngZone.run',
'before click',
'enter ngZone',
'begin onClick, ngZone = true',
'begin myAction, ngZone = false',
'begin myActionListener, ngZone = true',
'end myActionListener, ngZone = true',
'end myAction, ngZone = false',
'end onClick, ngZone = true',
'leave ngZone',
'after click',
'before incrementCounter',
Expand All @@ -201,7 +187,7 @@ describe('callWidgetFactoryWithConfig', () => {
});

it('calls the core with the correct init values', () => {
type MyWidget = Widget<{myValue: string}, {myValue: string}, Record<string, never>, Record<string, never>, Record<string, never>>;
type MyWidget = Widget<{myValue: string}, {myValue: string}, Record<string, never>, Record<string, never>>;

const factory: WidgetFactory<MyWidget> = (propsConfig) => {
const [{myValue$}, patch] = writablesForProps(
Expand All @@ -219,7 +205,6 @@ describe('callWidgetFactoryWithConfig', () => {
myValue$,
}),
api: {},
actions: {},
directives: {},
patch,
};
Expand Down
1 change: 0 additions & 1 deletion angular/headless/src/utils/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export const callWidgetFactoryWithConfig = <W extends Widget>({
...widget,
patch: zoneWrapper.outsideNgZone(widget.patch),
directives: zoneWrapper.outsideNgZoneWrapDirectivesObject(widget.directives),
actions: zoneWrapper.outsideNgZoneWrapFunctionsObject(widget.actions),
api: zoneWrapper.outsideNgZoneWrapFunctionsObject(widget.api),
};
Object.assign(res, wrappedWidget, {
Expand Down
4 changes: 2 additions & 2 deletions core-bootstrap/src/components/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ export interface AccordionProps extends CoreProps, AccordionExtraProps {
itemTransition: TransitionFn;
}

export type AccordionWidget = Widget<AccordionProps, AccordionState, AccordionApi, object, AccordionDirectives>;
export type AccordionWidget = Widget<AccordionProps, AccordionState, AccordionApi, AccordionDirectives>;

export interface AccordionItemState extends CoreItemState, AccordionItemExtraProps {}
export interface AccordionItemProps extends CoreItemProps, AccordionItemExtraProps {}

export type AccordionItemWidget = Widget<AccordionItemProps, AccordionItemState, AccordionItemApi, object, AccordionItemDirectives>;
export type AccordionItemWidget = Widget<AccordionItemProps, AccordionItemState, AccordionItemApi, AccordionItemDirectives>;

const defaultConfigExtraProps: AccordionExtraProps = {
itemStructure: undefined,
Expand Down
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/alert/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface AlertProps extends CoreProps, AlertExtraProps {
transition: TransitionFn;
}

export type AlertWidget = Widget<AlertProps, AlertState, AlertApi, object, AlertDirectives>;
export type AlertWidget = Widget<AlertProps, AlertState, AlertApi, AlertDirectives>;

const defaultConfigExtraProps: AlertExtraProps = {
structure: undefined,
Expand Down
3 changes: 1 addition & 2 deletions core-bootstrap/src/components/collapse/collapse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export interface CollapseDirectives {
transitionDirective: Directive;
}

export type CollapseWidget = Widget<CollapseProps, CollapseState, CollapseApi, object, CollapseDirectives>;
export type CollapseWidget = Widget<CollapseProps, CollapseState, CollapseApi, CollapseDirectives>;

const defaultCollapseConfig: CollapseProps = {
visible: true,
Expand Down Expand Up @@ -164,6 +164,5 @@ export function createCollapse(config?: PropsConfig<CollapseProps>): CollapseWid
directives: {
transitionDirective: bindDirectiveNoArg(transition.directives.directive),
},
actions: {},
};
}
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/modal/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface ModalApi<Data> extends Omit<CoreApi, 'patch'> {
patch: ModalWidget<Data>['patch'];
}

export type ModalWidget<Data> = Widget<ModalProps<Data>, ModalState<Data>, ModalApi<Data>, object, ModalDirectives>;
export type ModalWidget<Data> = Widget<ModalProps<Data>, ModalState<Data>, ModalApi<Data>, ModalDirectives>;

const defaultConfigExtraProps: ModalExtraProps<any> = {
contentData: undefined,
Expand Down
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/pagination/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ interface PaginationExtraProps {
export interface PaginationState extends CoreState, PaginationExtraProps {}
export interface PaginationProps extends CoreProps, PaginationExtraProps {}

export type PaginationWidget = Widget<PaginationProps, PaginationState, PaginationApi, object, PaginationDirectives>;
export type PaginationWidget = Widget<PaginationProps, PaginationState, PaginationApi, PaginationDirectives>;

const defaultConfigExtraProps: PaginationExtraProps = {
structure: undefined,
Expand Down
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/progressbar/progressbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface ProgressbarExtraProps {
export interface ProgressbarState extends CoreState, ProgressbarExtraProps {}
export interface ProgressbarProps extends CoreProps, ProgressbarExtraProps {}

export type ProgressbarWidget = Widget<ProgressbarProps, ProgressbarState, object, object, ProgressbarDirectives>;
export type ProgressbarWidget = Widget<ProgressbarProps, ProgressbarState, object, ProgressbarDirectives>;

const defaultConfigExtraProps: ProgressbarExtraProps = {
structure: undefined,
Expand Down
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/rating/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface RatingExtraProps {
export interface RatingState extends CoreState, RatingExtraProps {}
export interface RatingProps extends CoreProps, RatingExtraProps {}

export type RatingWidget = Widget<RatingProps, RatingState, RatingApi, object, RatingDirectives>;
export type RatingWidget = Widget<RatingProps, RatingState, RatingApi, RatingDirectives>;

const defaultConfigExtraProps: RatingExtraProps = {
star: ({fill}: StarContext) => String.fromCharCode(fill === 100 ? 9733 : 9734),
Expand Down
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface SelectExtraProps<Item> {
export interface SelectState<Item> extends CoreState<Item>, SelectExtraProps<Item> {}
export interface SelectProps<Item> extends CoreProps<Item>, SelectExtraProps<Item> {}

export type SelectWidget<Item> = Widget<SelectProps<Item>, SelectState<Item>, SelectApi<Item>, object, SelectDirectives<Item>>;
export type SelectWidget<Item> = Widget<SelectProps<Item>, SelectState<Item>, SelectApi<Item>, SelectDirectives<Item>>;

const defaultConfigExtraProps: SelectExtraProps<any> = {
badgeLabel: ({itemContext}: SelectItemContext<any>) => itemContext.item,
Expand Down
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface SliderExtraProps {
export interface SliderState extends CoreState, SliderExtraProps {}
export interface SliderProps extends CoreProps, SliderExtraProps {}

export type SliderWidget = Widget<SliderProps, SliderState, object, object, SliderDirectives>;
export type SliderWidget = Widget<SliderProps, SliderState, object, SliderDirectives>;

const defaultConfigExtraProps: SliderExtraProps = {
structure: undefined,
Expand Down
2 changes: 1 addition & 1 deletion core-bootstrap/src/components/toast/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface ToastProps extends CoreProps, ToastExtraProps {
transition: TransitionFn;
}

export type ToastWidget = Widget<ToastProps, ToastState, ToastApi, object, ToastDirectives>;
export type ToastWidget = Widget<ToastProps, ToastState, ToastApi, ToastDirectives>;

const defaultConfigExtraProps: ToastExtraProps = {
structure: undefined,
Expand Down
6 changes: 2 additions & 4 deletions core/src/components/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export interface AccordionDirectives {
accordionDirective: Directive;
}

export type AccordionWidget = Widget<AccordionProps, AccordionState, AccordionApi, object, AccordionDirectives>;
export type AccordionWidget = Widget<AccordionProps, AccordionState, AccordionApi, AccordionDirectives>;

export interface AccordionItemApi {
/**
Expand Down Expand Up @@ -304,7 +304,7 @@ export interface AccordionItemState extends AccordionItemCommonPropsAndState {
shouldBeInDOM: boolean;
}

export type AccordionItemWidget = Widget<AccordionItemProps, AccordionItemState, AccordionItemApi, object, AccordionItemDirectives>;
export type AccordionItemWidget = Widget<AccordionItemProps, AccordionItemState, AccordionItemApi, AccordionItemDirectives>;

const defaultAccordionConfig: AccordionProps = {
closeOthers: false,
Expand Down Expand Up @@ -482,7 +482,6 @@ export function createAccordionItem(config?: PropsConfig<AccordionItemProps>): A
visible$.update((c: boolean) => !c);
},
},
actions: {},
directives: {
toggleDirective,
buttonDirective: mergeDirectives(
Expand Down Expand Up @@ -552,7 +551,6 @@ export function factoryCreateAccordion(
return {
...stateStores({itemWidgets$, className$}),
patch,
actions: {},
api: {
expand: (id: string) => {
getItem(itemWidgets$(), id)?.api.expand();
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/alert/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface AlertState extends CommonAlertState {}
export interface AlertProps extends CommonAlertProps {}
export interface AlertApi extends CommonAlertApi {}
export interface AlertDirectives extends CommonAlertDirectives {}
export type AlertWidget = Widget<AlertProps, AlertState, AlertApi, object, AlertDirectives>;
export type AlertWidget = Widget<AlertProps, AlertState, AlertApi, AlertDirectives>;

/**
* Retrieve a shallow copy of the default alert config
Expand Down
3 changes: 1 addition & 2 deletions core/src/components/alert/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export interface CommonAlertDirectives {
transitionDirective: Directive;
}

export type CommonAlertWidget = Widget<CommonAlertProps, CommonAlertState, CommonAlertApi, object, CommonAlertDirectives>;
export type CommonAlertWidget = Widget<CommonAlertProps, CommonAlertState, CommonAlertApi, CommonAlertDirectives>;

const defaultCommonAlertConfig: CommonAlertProps = {
visible: true,
Expand Down Expand Up @@ -191,6 +191,5 @@ export function createCommonAlert(config?: PropsConfig<CommonAlertProps>): Commo
directives: {
transitionDirective: bindDirectiveNoArg(transition.directives.directive),
},
actions: {},
};
}
3 changes: 1 addition & 2 deletions core/src/components/modal/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export interface ModalDirectives {
/**
* Modal widget.
*/
export type ModalWidget = Widget<ModalProps, ModalState, ModalApi, object, ModalDirectives>;
export type ModalWidget = Widget<ModalProps, ModalState, ModalApi, ModalDirectives>;

const defaultConfig: ModalProps = {
animated: true,
Expand Down Expand Up @@ -507,7 +507,6 @@ export function createModal(config$?: PropsConfig<ModalProps>): ModalWidget {
},
patch,
},
actions: {},
};

return res;
Expand Down
3 changes: 1 addition & 2 deletions core/src/components/pagination/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export interface PaginationDirectives {
pageLast: Directive;
}

export type PaginationWidget = Widget<PaginationProps, PaginationState, PaginationApi, object, PaginationDirectives>;
export type PaginationWidget = Widget<PaginationProps, PaginationState, PaginationApi, PaginationDirectives>;

const PAGE_LINK_DEFAULT = '#';

Expand Down Expand Up @@ -493,7 +493,6 @@ export function createPagination(config?: PropsConfig<PaginationProps>): Paginat
...stateProps,
}),
patch,
actions: {},
api: {
/**
* Set the current page pageNumber (starting from 1)
Expand Down
3 changes: 1 addition & 2 deletions core/src/components/progressbar/progressbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface ProgressbarProps extends ProgressbarCommonPropsAndState {
ariaValueTextFn: (value: number, minimum: number, maximum: number) => string | undefined;
}

export type ProgressbarWidget = Widget<ProgressbarProps, ProgressbarState, object, object, ProgressbarDirectives>;
export type ProgressbarWidget = Widget<ProgressbarProps, ProgressbarState, object, ProgressbarDirectives>;

const defaultConfig: ProgressbarProps = {
min: 0,
Expand Down Expand Up @@ -163,6 +163,5 @@ export function createProgressbar(config?: PropsConfig<ProgressbarProps>): Progr
},
})),
},
actions: {},
};
}
3 changes: 1 addition & 2 deletions core/src/components/rating/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export interface RatingApi {
leave(): void;
}

export type RatingWidget = Widget<RatingProps, RatingState, RatingApi, object, RatingDirectives>;
export type RatingWidget = Widget<RatingProps, RatingState, RatingApi, RatingDirectives>;

const defaultConfig: RatingProps = {
rating: 0,
Expand Down Expand Up @@ -285,7 +285,6 @@ export function createRating(config?: PropsConfig<RatingProps>): RatingWidget {
...stateProps,
}),
patch,
actions: {},
directives: {
containerDirective: createAttributesDirective(() => ({
events: {
Expand Down
3 changes: 1 addition & 2 deletions core/src/components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export interface SelectDirectives<Item> {
badgeCloseButtonDirective: Directive<ItemContext<Item>>;
}

export type SelectWidget<Item> = Widget<SelectProps<Item>, SelectState<Item>, SelectApi<Item>, object, SelectDirectives<Item>>;
export type SelectWidget<Item> = Widget<SelectProps<Item>, SelectState<Item>, SelectApi<Item>, SelectDirectives<Item>>;

const defaultConfig: SelectProps<any> = {
id: undefined,
Expand Down Expand Up @@ -732,7 +732,6 @@ export function createSelect<Item>(config?: PropsConfig<SelectProps<Item>>): Sel
inputDirective,
badgeCloseButtonDirective,
},
actions: {},
};

return widget;
Expand Down
3 changes: 1 addition & 2 deletions core/src/components/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export interface SliderDirectives {
handleLabelDisplayDirective: Directive<{index: number}>;
}

export type SliderWidget = Widget<SliderProps, SliderState, object, object, SliderDirectives>;
export type SliderWidget = Widget<SliderProps, SliderState, object, SliderDirectives>;

const defaultSliderConfig: SliderProps = {
min: 0,
Expand Down Expand Up @@ -865,7 +865,6 @@ export function createSlider(config?: PropsConfig<SliderProps>): SliderWidget {
},
})),
},
actions: {},
};

return widget;
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/toast/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface ToastApi extends CommonAlertApi {}

export interface ToastDirectives extends CommonAlertDirectives, ExtraDirectives {}

export type ToastWidget = Widget<ToastProps, ToastState, ToastApi, object, ToastDirectives>;
export type ToastWidget = Widget<ToastProps, ToastState, ToastApi, ToastDirectives>;

const toastDefaultConfig: ToastExtraProps = {
autoHide: true,
Expand Down
1 change: 0 additions & 1 deletion core/src/services/extendWidget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ describe(`extendWidgetProps`, () => {
myOtherNewProp: 'value',
},
});
expect(Object.keys(customWidget.actions)).toEqual(Object.keys(originalWidget.actions));
expect(Object.keys(customWidget.api)).toEqual(Object.keys(originalWidget.api));
expect(Object.keys(customWidget.directives)).toEqual(Object.keys(originalWidget.directives));
expect(Object.keys(customWidget.stores)).toEqual([...Object.keys(originalWidget.stores), 'myNewProp$', 'myOtherNewProp$']);
Expand Down
1 change: 0 additions & 1 deletion core/src/services/extendWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export type ExtendWidgetProps<W extends Widget, ExtraProps extends object, Extra
ExtendWidgetAdaptSlotWidgetProps<WidgetProps<W>, ExtraProps, ExtraDirectives>,
ExtendWidgetAdaptSlotWidgetProps<WidgetState<W>, ExtraProps, ExtraDirectives>,
W['api'],
W['actions'],
ExtendWidgetInterfaces<W['directives'], ExtraDirectives>
>;

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/floatingUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const defaultConfig: FloatingUIProps = {
arrowOptions: {},
};

export type FloatingUI = Omit<Widget<FloatingUIProps, FloatingUIState, object, object, FloatingUIDirectives>, 'api' | 'actions'>;
export type FloatingUI = Omit<Widget<FloatingUIProps, FloatingUIState, object, FloatingUIDirectives>, 'api'>;

/**
* Create a floating UI service.
Expand Down
3 changes: 1 addition & 2 deletions core/src/services/transitions/baseTransitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export interface TransitionDirectives {
directive: Directive<void | Partial<TransitionProps>>;
}

export type TransitionWidget = Widget<TransitionProps, TransitionState, TransitionApi, object, TransitionDirectives>;
export type TransitionWidget = Widget<TransitionProps, TransitionState, TransitionApi, TransitionDirectives>;

const neverEndingPromise = new Promise<never>(noop);

Expand Down Expand Up @@ -361,7 +361,6 @@ export const createTransition = (config?: PropsConfig<TransitionProps>): Transit
directives: {
directive,
},
actions: {},
api: {
show: toggle.bind(null, true),
hide: toggle.bind(null, false),
Expand Down
Loading

0 comments on commit 59853ba

Please sign in to comment.