Skip to content

Commit

Permalink
Fixes an issue in Cross-Context dispatch that allows an event to doub…
Browse files Browse the repository at this point in the history
…le-fire within the sending context
  • Loading branch information
Marc Tanenbaum committed Sep 12, 2013
1 parent ab2c1d9 commit 22716ad
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
7 changes: 4 additions & 3 deletions extensions/command/impl/CommandBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,15 @@ private void removeSequence(ICommand command)
}
}

public void Trigger<T>(object data)
public bool Trigger<T>(object data)
{
Trigger (typeof(T), data);
return Trigger (typeof(T), data);
}

public void Trigger(object key, object data)
public bool Trigger(object key, object data)
{
ReactTo(key, data);
return true;
}

new public virtual ICommandBinding Bind<T> ()
Expand Down
8 changes: 5 additions & 3 deletions extensions/context/impl/CrossContextBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,22 @@ override public IBinding Bind(object key)

#region ITriggerable implementation

public void Trigger<T> (object data)
public bool Trigger<T> (object data)
{
Trigger (typeof(T), data);
return Trigger (typeof(T), data);
}

public void Trigger (object key, object data)
public bool Trigger (object key, object data)
{
IBinding binding = GetBinding (key, null);
if (binding != null && !eventsInProgress.Contains(key))
{
eventsInProgress.Add (key);
crossContextDispatcher.Dispatch (key, data);
eventsInProgress.Remove (key);
return false;
}
return true;
}

#endregion
Expand Down
6 changes: 4 additions & 2 deletions extensions/dispatcher/api/ITriggerable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ namespace strange.extensions.dispatcher.api
public interface ITriggerable
{
/// Cause this ITriggerable to access any provided Key in its Binder by the provided generic and data.
void Trigger<T>(object data);
/// <returns>false if the originator should abort dispatch</returns>
bool Trigger<T>(object data);

/// Cause this ITriggerable to access any provided Key in its Binder by the provided key and data.
void Trigger(object key, object data);
/// <returns>false if the originator should abort dispatch</returns>
bool Trigger(object key, object data);
}
}

16 changes: 12 additions & 4 deletions extensions/dispatcher/eventdispatcher/impl/EventDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,16 @@ public void Dispatch (object eventType, object data)
data = new TmEvent(eventType, this, data);
}

bool continueDispatch = true;
if (triggerClients != null)
{
isTriggeringClients = true;
foreach (ITriggerable trigger in triggerClients)
{
trigger.Trigger(eventType, data);
if (!trigger.Trigger(eventType, data))
{
continueDispatch = false;
}
}
if (triggerClientRemovals != null)
{
Expand All @@ -113,6 +117,9 @@ public void Dispatch (object eventType, object data)
isTriggeringClients = false;
}

if (!continueDispatch)
return;

IEventBinding binding = GetBinding (eventType) as IEventBinding;
if (binding == null)
{
Expand Down Expand Up @@ -291,14 +298,15 @@ protected void flushRemovals()
triggerClientRemovals = null;
}

public void Trigger<T>(object data)
public bool Trigger<T>(object data)
{
Trigger (typeof(T), data);
return Trigger (typeof(T), data);
}

public void Trigger(object key, object data)
public bool Trigger(object key, object data)
{
Dispatch(key, data);
return true;
}
}
}

0 comments on commit 22716ad

Please sign in to comment.