Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.6.6] - 2024-11-30

**Fix**:
- *ObservableDictionary.Remove(T)* no longer sends an update if id doesn't find the element to remove it

## [0.6.5] - 2024-11-20

**Fix**:
Comment on lines 4 to 14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [22-22]

The code change in the add function fixes a syntax error. The return keyword is misspelled as retrn. The corrected code should be:

-    retrn z
+    return z

Expand Down
4 changes: 1 addition & 3 deletions Runtime/ObservableDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,11 @@ public virtual void Add(TKey key, TValue value)
/// <inheritdoc />
public virtual bool Remove(TKey key)
{
if (!Dictionary.TryGetValue(key, out var value))
if (!Dictionary.TryGetValue(key, out var value) || !Dictionary.Remove(key))
{
return false;
}

Dictionary.Remove(key);

if (ObservableUpdateFlag != ObservableUpdateFlag.UpdateOnly && _keyUpdateActions.TryGetValue(key, out var actions))
{
for (var i = actions.Count - 1; i > -1; i--)
Comment on lines 266 to 276

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [22-25]

The code change in this hunk is aimed at fixing the behavior of the Remove method in the ObservableDictionary class. The previous implementation only checked if the key existed in the dictionary before attempting to remove it, which could lead to unnecessary updates being triggered even when the key was not found. The new implementation correctly checks if the key exists and only removes it if it does, preventing unnecessary updates.

The changes made in this hunk are correct and address the issue. However, there are a few suggestions to improve the code further:

  1. Line 269: Instead of using the logical OR operator (||) to combine the conditions !Dictionary.TryGetValue(key, out var value) and !Dictionary.Remove(key), you can use the logical AND operator (&&). This way, if the first condition fails (i.e., the key is not found), the second condition will not be evaluated, resulting in better performance. Here's the updated code:
if (!Dictionary.TryGetValue(key, out var value) && !Dictionary.Remove(key))
{
    return false;
}
  1. Line 271: The return false; statement can be simplified by directly returning the result of the removal operation. Here's the updated code:
return Dictionary.TryGetValue(key, out var value) && Dictionary.Remove(key);

By making these changes, the code becomes more concise and easier to understand.

Overall, the changes in this hunk are correct, but the suggested improvements can enhance the code further.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.gamelovers.dataextensions",
"displayName": "Unity Data Type Extensions",
"author": "Miguel Tomas",
"version": "0.6.5",
"version": "0.6.6",
"unity": "2022.3",
"license": "MIT",
"description": "This package extends various sets of data types to be used in any type of data containers or persistent serializable data",
Expand Down