Skip to content

Commit 907983f

Browse files
Merge pull request #109 from PaulNonatomic/develop
Develop
2 parents a576857 + 390d5c8 commit 907983f

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## [0.8.3-beta] - Sept 11, 2024
4+
- SharedData.ClearData is now Obsolete and will be removed in a future release. Use SharedData.ClearAllData instead.
5+
- Added SharedData.ClearAllData method to clear all shared data.
6+
- Added SharedData.RemoveData(string key) method to remove a specific key from the shared data.
7+
- Added SharedData.GetKeys() method to return all keys in the shared data.
8+
39
## [0.8.2-beta] - Sept 09, 2024
410
- Added TryGetData and HasData methods to the SharedData class
511

Runtime/Data/SharedData.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,25 @@ public interface ISharedData
88
{
99
event Action<string, object> OnDataChanged;
1010
event Action OnDataCleared;
11+
event Action<string> OnDataRemoved;
1112

1213
T GetData<T>(string key);
1314
bool TryGetData<T>(string key, out T value);
1415
bool HasData(string key);
1516
void SetData<T>(string key, T value);
17+
void RemoveData(string key);
18+
void ClearAllData();
19+
IEnumerable<string> GetKeys();
20+
21+
[Obsolete("Use ClearAllData() instead. This method will be removed in a future version.")]
1622
void ClearData();
1723
}
1824

1925
public class SharedData : ISharedData
2026
{
2127
public event Action<string, object> OnDataChanged;
2228
public event Action OnDataCleared;
29+
public event Action<string> OnDataRemoved;
2330

2431
private readonly Dictionary<string, object> _data = new Dictionary<string, object>();
2532
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
@@ -95,7 +102,23 @@ public void SetData<T>(string key, T value)
95102
}
96103
}
97104

98-
public void ClearData()
105+
public void RemoveData(string key)
106+
{
107+
_lock.EnterWriteLock();
108+
try
109+
{
110+
if (_data.Remove(key))
111+
{
112+
OnDataRemoved?.Invoke(key);
113+
}
114+
}
115+
finally
116+
{
117+
_lock.ExitWriteLock();
118+
}
119+
}
120+
121+
public void ClearAllData()
99122
{
100123
_lock.EnterWriteLock();
101124
try
@@ -108,5 +131,24 @@ public void ClearData()
108131
_lock.ExitWriteLock();
109132
}
110133
}
134+
135+
[Obsolete("Use ClearAllData() instead. This method will be removed in a future version.")]
136+
public void ClearData()
137+
{
138+
ClearAllData();
139+
}
140+
141+
public IEnumerable<string> GetKeys()
142+
{
143+
_lock.EnterReadLock();
144+
try
145+
{
146+
return _data.Keys;
147+
}
148+
finally
149+
{
150+
_lock.ExitReadLock();
151+
}
152+
}
111153
}
112154
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.nonatomic.visualstatemachinev2",
3-
"version": "0.8.2-beta",
3+
"version": "0.8.3-beta",
44
"displayName": "Visual State Machine V2",
55
"description": "Visual State Machine V2",
66
"unity": "2022.3",

0 commit comments

Comments
 (0)