-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mvux): Add support for hot-reload in dynamic feed
- Loading branch information
Showing
6 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/Uno.Extensions.Reactive/Sources/Dynamic/Dependencies/HotReload/HotReloadDependency.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using Microsoft.Extensions.Logging; | ||
using Uno.Extensions.Reactive.Core.HotReload; | ||
using Uno.Extensions.Reactive.Logging; | ||
|
||
namespace Uno.Extensions.Reactive.Sources; | ||
|
||
/// <summary> | ||
/// A dependency that will trigger a feed execution when the application is updated (hot-reload). | ||
/// </summary> | ||
internal sealed class HotReloadDependency : IDependency | ||
{ | ||
private static int _count; | ||
private readonly int _id = Interlocked.Increment(ref _count); | ||
|
||
public HotReloadDependency(FeedSession session) | ||
{ | ||
var feedDelegate = session.CoreExecutionAction; | ||
var feedDelegateType = feedDelegate.Method.DeclaringType; | ||
|
||
if (this.Log().IsEnabled(LogLevel.Information)) | ||
{ | ||
this.Log().Info($"[DYNAMIC_RELOAD] #{_id} Dynamic feed listening for updates of delegate {feedDelegateType?.FullName}->{feedDelegate.Method.Name}"); | ||
} | ||
|
||
HotReloadService.ApplicationUpdated += OnUpdate; | ||
session.Token.Register(() => HotReloadService.ApplicationUpdated -= OnUpdate); | ||
|
||
void OnUpdate(Type[] types) | ||
{ | ||
if (types.Contains(feedDelegateType)) | ||
{ | ||
if (this.Log().IsEnabled(LogLevel.Information)) | ||
{ | ||
this.Log().Info($"[DYNAMIC_RELOAD] #{_id} Delegate {feedDelegateType?.FullName}->{feedDelegate.Method.Name} has been updated"); | ||
} | ||
|
||
session.Execute(new ExecuteRequest(this, "Hot reloading the updated delegate")); | ||
} | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async ValueTask OnExecuting(FeedExecution execution, CancellationToken ct) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async ValueTask OnExecuted(FeedExecution execution, FeedExecutionResult result, CancellationToken ct) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters