Skip to content

Commit 8be260a

Browse files
committed
Change TryLoadFromDto to not create a new instance of the domain object if it already exists (in most cases, it doesn't)
1 parent d860828 commit 8be260a

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Assets/Plugins/StreamChat/Core/Helpers/ILoadableFromExt.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using StreamChat.Core.InternalDTO.Models;
23
using StreamChat.Core.LowLevelClient;
4+
using StreamChat.Core.LowLevelClient.Models;
35

46
namespace StreamChat.Core.Helpers
57
{
@@ -8,7 +10,9 @@ namespace StreamChat.Core.Helpers
810
/// </summary>
911
internal static class ILoadableFromExt
1012
{
11-
//StreamTodo: rename to TryCreateFromDto? It's misleading because it creates new instance which you need to replace
13+
/// <summary>
14+
/// Load domain object from the DTO. If the loadable is null, creates a new instance of the domain object.
15+
/// </summary>
1216
public static TDomain TryLoadFromDto<TDto, TDomain>(this ILoadableFrom<TDto, TDomain> loadable, TDto dto)
1317
where TDomain : ILoadableFrom<TDto, TDomain>, new()
1418
{
@@ -17,7 +21,7 @@ public static TDomain TryLoadFromDto<TDto, TDomain>(this ILoadableFrom<TDto, TDo
1721
return default;
1822
}
1923

20-
return new TDomain().LoadFromDto(dto);
24+
return loadable != null ? loadable.LoadFromDto(dto) : new TDomain().LoadFromDto(dto);
2125
}
2226

2327
public static TDomain UpdateFromDto<TDto, TDomain>(this ILoadableFrom<TDto, TDomain> loadable, TDto dto)

0 commit comments

Comments
 (0)