Skip to content

Commit

Permalink
fix: async function delegates not being awaited
Browse files Browse the repository at this point in the history
  • Loading branch information
mergehez committed Oct 24, 2024
1 parent e18443e commit 71f968c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions InertiaNetCore/Models/InertiaProps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ internal async Task<InertiaProps> ToProcessedProps(bool isPartial, List<string>
if(isPartial && value is not IAlwaysProp && !partials.Contains(key, StringComparer.InvariantCultureIgnoreCase))
continue;

props.Add(key, value switch
var computed = value switch
{
Func<Task<object?>> f => await f.Invoke(),
Func<object?> f => f.Invoke(),
Delegate d => d.DynamicInvoke(),
IInvokableProp l => await l.InvokeToObject(),
_ => value
});
};

if (computed is Task task)
props.Add(key, await (task as dynamic)); // TODO: find a solution to avoid dynamic
else
props.Add(key, computed);
}

return props;
Expand Down

0 comments on commit 71f968c

Please sign in to comment.