This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "ShrinkContext.EventBusAdapter.Runtime",
|
||||
"rootNamespace": "ShrinkContext.EventBusAdapter",
|
||||
"references": [
|
||||
"ShrinkContext.Core.Runtime",
|
||||
"ShrinkEventBus.Runtime",
|
||||
"UniTask"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"autoReferenced": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: edea41497d7034e4c970a7368a156da4
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using ShrinkContext;
|
||||
using ShrinkEventBus;
|
||||
|
||||
namespace ShrinkContext.EventBusAdapter
|
||||
{
|
||||
/// <summary>
|
||||
/// 把生成的 ShrinkEventBus 绑定包装为可逆效应。
|
||||
/// </summary>
|
||||
public static class ShrinkEventBusEffects
|
||||
{
|
||||
/// <summary>
|
||||
/// 激活生成的 [ShrinkSubscribe] 绑定,并在 Context 回滚时统一释放。
|
||||
/// </summary>
|
||||
public static ShrinkEffectHandle EffectAttach(this ShrinkCtx ctx, object target,
|
||||
ShrinkBusKey? defaultBus = null)
|
||||
{
|
||||
if (ctx == null)
|
||||
throw new ArgumentNullException(nameof(ctx));
|
||||
if (target == null)
|
||||
throw new ArgumentNullException(nameof(target));
|
||||
|
||||
var binding = EventBus.Attach(target, defaultBus);
|
||||
return ctx.EffectInverse(() =>
|
||||
{
|
||||
binding.Dispose();
|
||||
return UniTask.CompletedTask;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e897f289a1563c34eb3c992463f66fbc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user