From 6b4c182806b141d432f4e25a194e15aacb421128 Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Mon, 27 May 2024 11:00:40 +0200 Subject: [PATCH] [Glitch] Fix `createDataLoadingThunk` to allow actions without arguments Port 6a75e1c8c82a1625867ea69be3d0c55697448f4e to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/store/typed_functions.ts | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/app/javascript/flavours/glitch/store/typed_functions.ts b/app/javascript/flavours/glitch/store/typed_functions.ts index 0392f373c0..dae37e6225 100644 --- a/app/javascript/flavours/glitch/store/typed_functions.ts +++ b/app/javascript/flavours/glitch/store/typed_functions.ts @@ -89,21 +89,17 @@ type OnData = ( }, ) => ReturnedData | DiscardLoadData | Promise; +type ArgsType = Record | undefined; + // Overload when there is no `onData` method, the payload is the `onData` result -export function createDataLoadingThunk< - LoadDataResult, - Args extends Record, ->( +export function createDataLoadingThunk( name: string, loadData: (args: Args) => Promise, thunkOptions?: AppThunkOptions, ): ReturnType>; // Overload when the `onData` method returns discardLoadDataInPayload, then the payload is empty -export function createDataLoadingThunk< - LoadDataResult, - Args extends Record, ->( +export function createDataLoadingThunk( name: string, loadData: (args: Args) => Promise, onDataOrThunkOptions?: @@ -113,10 +109,7 @@ export function createDataLoadingThunk< ): ReturnType>; // Overload when the `onData` method returns nothing, then the mayload is the `onData` result -export function createDataLoadingThunk< - LoadDataResult, - Args extends Record, ->( +export function createDataLoadingThunk( name: string, loadData: (args: Args) => Promise, onDataOrThunkOptions?: AppThunkOptions | OnData, @@ -126,7 +119,7 @@ export function createDataLoadingThunk< // Overload when there is an `onData` method returning something export function createDataLoadingThunk< LoadDataResult, - Args extends Record, + Args extends ArgsType, Returned, >( name: string, @@ -162,7 +155,7 @@ export function createDataLoadingThunk< */ export function createDataLoadingThunk< LoadDataResult, - Args extends Record, + Args extends ArgsType, Returned, >( name: string,