Skip to content

Commit e1a3a82

Browse files
committed
-
1 parent 45806cc commit e1a3a82

File tree

6 files changed

+35
-105
lines changed

6 files changed

+35
-105
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Changelog
22
All notable changes to this package will be documented in this file.
33

4+
## [1.2.2] - 2023-04-20
5+
6+
### Fixed
7+
- The FuncFlux and FuncFluxParam as design is planned to only add one per key, but you can add multiple keys instead, thats why we reduce the complexity of optimization to just use Func< TResult > as TStorage
8+
9+
### Removed
10+
- Removed dictionary_read in ActionFlux, ActionFluxParam, FuncFlux and FuncFluxParam
11+
412
## [1.2.1] - 2023-04-17
513

614
### Fixed

Runtime/Core/Internal/ActionFlux.cs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ internal sealed class ActionFlux<TKey> : IFlux<TKey, Action>
3434
// internal Dictionary<TKey, Action> dictionary = new Dictionary<TKey, Action>();
3535
// internal Dictionary<TKey, List<Action>> dictionary = new Dictionary<TKey, List<Action>>();
3636
internal Dictionary<TKey, HashSet<Action>> dictionary = new Dictionary<TKey, HashSet<Action>>();
37-
/// <summary>
38-
/// A Read Only dictionary wich contains dictionary field
39-
/// </summary>
40-
// internal readonly IReadOnlyDictionary<TKey, Action> dictionary_read = null;
41-
internal readonly IReadOnlyDictionary<TKey, HashSet<Action>> dictionary_read = null;
42-
/// <summary>
43-
/// Constructor of ActionFLux
44-
/// </summary>
45-
public ActionFlux()
46-
{
47-
dictionary_read = dictionary;
48-
}
4937
///<summary>
5038
/// Subscribes an event to the action dictionary if the given condition is met
5139
///</summary>
@@ -54,36 +42,19 @@ public ActionFlux()
5442
///<param name="action">Action to execute when the event is triggered</param>
5543
void IStore<TKey, Action>.Store(in bool condition, TKey key, Action action)
5644
{
57-
if(dictionary_read.TryGetValue(key, out var values))
45+
if(dictionary.TryGetValue(key, out var values))
5846
{
5947
if (condition) values.Add(action);
6048
else values.Remove(action);
6149
}
6250
else if (condition) dictionary.Add(key, new HashSet<Action>(){action});
63-
// if(dictionary_read.TryGetValue(key, out var values))
64-
// {
65-
// if (condition) values.Add(action);
66-
// else values.Remove(action);
67-
// }
68-
// else if (condition) dictionary.Add(key, new List<Action>(){action});
69-
// if(dictionary_read.ContainsKey(key))
70-
// {
71-
// if (condition) dictionary[key] += action;
72-
// else dictionary[key] -= action;
73-
// }
74-
// else if (condition) dictionary.Add(key, action);
7551
}
7652
///<summary>
7753
/// Triggers the function stored in the dictionary with the specified key.
7854
///</summary>
7955
void IFlux<TKey, Action>.Dispatch(TKey key)
8056
{
81-
// if(dictionary_read.TryGetValue(key, out var _actions)) _actions?.Invoke();
82-
// if(dictionary_read.TryGetValue(key, out var _actions))
83-
// {
84-
// for (int i = 0; i < _actions.Count; i++) _actions[i].Invoke();
85-
// }
86-
if(dictionary_read.TryGetValue(key, out var _actions))
57+
if(dictionary.TryGetValue(key, out var _actions))
8758
{
8859
foreach (var item in _actions) item.Invoke();
8960
}

Runtime/Core/Internal/ActionFluxParam.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ public ActionFluxParam()
5151
///<param name="action">Action to execute when the event is triggered</param>
5252
void IStore<TKey, Action<TValue>>.Store(in bool condition, TKey key, Action<TValue> action)
5353
{
54-
// if(dictionary_read.ContainsKey(key))
55-
// {
56-
// if (condition) dictionary[key] += action;
57-
// else dictionary[key] -= action;
58-
// }
59-
// else if (condition) dictionary.Add(key, action);
6054
if(dictionary_read.TryGetValue(key, out var values))
6155
{
6256
if (condition) values.Add(action);
@@ -69,11 +63,6 @@ void IStore<TKey, Action<TValue>>.Store(in bool condition, TKey key, Action<TVal
6963
///</summary>
7064
void IFluxParam<TKey, TValue, Action<TValue>>.Dispatch(TKey key, TValue param)
7165
{
72-
// if(dictionary_read.TryGetValue(key, out var _actions)) _actions?.Invoke(param);
73-
// if(dictionary_read.TryGetValue(key, out var _actions))
74-
// {
75-
// for (int i = 0; i < _actions.Count; i++) _actions[i].Invoke(param);
76-
// }
7766
if(dictionary_read.TryGetValue(key, out var _actions))
7867
{
7968
foreach (var item in _actions) item.Invoke(param);

Runtime/Core/Internal/FuncFlux.cs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,51 +34,34 @@ internal sealed class FuncFlux<TKey, TReturn> : IFluxReturn<TKey, TReturn, Func<
3434
/// <summary>
3535
/// A dictionary that stores functions with no parameters and a return value of type `TReturn`.
3636
/// </summary>
37-
internal readonly Dictionary<TKey, List<Func<TReturn>>> dictionary = new Dictionary<TKey, List<Func<TReturn>>>();
38-
/// <summary>
39-
/// A Read Only dictionary wich contains dictionary field
40-
/// </summary>
41-
internal readonly IReadOnlyDictionary<TKey, List<Func<TReturn>>> dictionary_read = null;
42-
/// <summary>
43-
/// Constructor of FuncFlux
44-
/// </summary>
45-
public FuncFlux()
46-
{
47-
dictionary_read = dictionary;
48-
}
37+
internal readonly Dictionary<TKey, Func<TReturn>> dictionary = new Dictionary<TKey, Func<TReturn>>();
4938
/// <summary>
5039
/// Subscribes the provided function to the dictionary with the specified key when `condition` is true.
5140
/// If `condition` is false and the dictionary contains the specified key, the function is removed from the dictionary.
5241
/// </summary>
5342
void IStore<TKey, Func<TReturn>>.Store(in bool condition, TKey key, Func<TReturn> func)
5443
{
55-
// if(dictionary_read.ContainsKey(key))
56-
// {
57-
// if (condition) dictionary[key] += func;
58-
// else dictionary[key] -= func;
59-
// }
60-
// else if (condition) dictionary.Add(key, func);
61-
if(dictionary_read.TryGetValue(key, out var values))
44+
if(dictionary.TryGetValue(key, out var values))
6245
{
63-
if (condition) values.Add(func);
64-
else values.Remove(func);
46+
if (condition) dictionary[key] += func;
47+
else
48+
{
49+
values -= func;
50+
if (values is null) dictionary.Remove(key);
51+
else dictionary[key] = values;
52+
}
6553
}
66-
else if (condition) dictionary.Add(key, new List<Func<TReturn>>(){func});
54+
else if (condition) dictionary.Add(key, func);
6755
}
6856
// <summary>
6957
/// Triggers the function stored in the dictionary with the specified key and returns its return value.
7058
/// If the dictionary does not contain the specified key, returns the default value of type `TReturn`.
7159
/// </summary>
7260
TReturn IFluxReturn<TKey, TReturn, Func<TReturn>>.Dispatch(TKey key)
7361
{
74-
// if(dictionary_read.TryGetValue(key, out var _actions)) return _actions.Invoke();
75-
if(dictionary_read.TryGetValue(key, out var _actions))
62+
if(dictionary.TryGetValue(key, out var _actions))
7663
{
77-
for (int i = 0; i < _actions.Count - 1; i++)
78-
{
79-
_actions[i].Invoke();
80-
}
81-
return _actions[_actions.Count-1].Invoke();
64+
return _actions.Invoke();
8265
}
8366
return default;
8467
}

Runtime/Core/Internal/FuncFluxParam.cs

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,55 +35,34 @@ internal sealed class FuncFluxParam<TKey, TParam, TReturn> : IFluxParamReturn<TK
3535
/// <summary>
3636
/// A dictionary that stores functions with one parameter of type `TParam` and a return value of type `TReturn`.
3737
/// </summary>
38-
internal readonly Dictionary<TKey, List<Func<TParam, TReturn>>> dictionary = new Dictionary<TKey, List<Func<TParam, TReturn>>>();
39-
/// <summary>
40-
/// A Read Only dictionary wich contains dictionary field
41-
/// </summary>
42-
internal readonly IReadOnlyDictionary<TKey, List<Func<TParam, TReturn>>> dictionary_read = null;
43-
/// <summary>
44-
/// Constructor of FuncFlux
45-
/// </summary>
46-
public FuncFluxParam()
47-
{
48-
dictionary_read = dictionary;
49-
}
38+
internal readonly Dictionary<TKey, Func<TParam, TReturn>> dictionary = new Dictionary<TKey, Func<TParam, TReturn>>();
5039
/// <summary>
5140
/// Subscribes the provided function to the dictionary with the specified key when `condition` is true.
5241
/// If `condition` is false and the dictionary contains the specified key, the function is removed from the dictionary.
5342
/// </summary>
5443
void IStore<TKey, Func<TParam, TReturn>>.Store(in bool condition, TKey key, Func<TParam, TReturn> func)
5544
{
56-
// if(dictionary_read.ContainsKey(key))
57-
// {
58-
// if (condition) dictionary[key] += func;
59-
// else dictionary[key] -= func;
60-
// }
61-
// else if (condition) dictionary.Add(key, func);
62-
if(dictionary_read.TryGetValue(key, out var values))
45+
if(dictionary.TryGetValue(key, out var values))
6346
{
64-
if (condition) values.Add(func);
65-
else values.Remove(func);
47+
if (condition) dictionary[key] += func;
48+
else
49+
{
50+
values -= func;
51+
if (values is null) dictionary.Remove(key);
52+
else dictionary[key] = values;
53+
}
6654
}
67-
else if (condition) dictionary.Add(key, new List<Func<TParam, TReturn>>(){func});
55+
else if (condition) dictionary.Add(key, func);
6856
}
6957
/// <summary>
7058
/// Triggers the function stored in the dictionary with the specified key and parameter, and returns its return value.
7159
/// If the dictionary does not contain the specified key, returns the default value of type `TReturn`.
7260
/// </summary>
7361
TReturn IFluxParamReturn<TKey, TParam, TReturn, Func<TParam, TReturn>>.Dispatch(TKey key, TParam param)
7462
{
75-
// if(dictionary_read.TryGetValue(key, out var _actions)) return _actions.Invoke(param);
76-
// if(dictionary_read.TryGetValue(key, out var _actions))
77-
// {
78-
// for (int i = 0; i < _actions.Count; i++) _actions[i].Invoke(param);
79-
// }
80-
if(dictionary_read.TryGetValue(key, out var _actions))
63+
if(dictionary.TryGetValue(key, out var _actions))
8164
{
82-
for (int i = 0; i < _actions.Count - 1; i++)
83-
{
84-
_actions[i].Invoke(param);
85-
}
86-
return _actions[_actions.Count-1].Invoke(param);
65+
return _actions.Invoke(param);
8766
}
8867
return default;
8968
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.kingdox.uniflux",
33
"displayName": "UniFlux",
44
"author": "Xavier Thomas Peter Arpa López ('Kingdox')",
5-
"version": "1.2.1",
5+
"version": "1.2.2",
66
"unity": "2019.1",
77
"description": "Provides Flux flow integration to Unity.",
88
"keywords": [

0 commit comments

Comments
 (0)