As a Roblox developer, it is currently very hard to copy dictionaries/arrays. You either have to create a function to do it for you, or just re-use the same dictionaries. This becomes especially annoying when trying to handle states using something like Rodux.
Rodux is similar to Redux, it allows for quite nice state handling, but it becomes quite tedious to do something like this for each action type:
return {
EquippedShip = state.EquippedShip;
SelectedShip = state.SelectedShip;
ShipSelection = state.ShipSelection;
ShipSelectionVisible = action.payload;
}
And it gets even worse when you have to do this for each and every action type. Now, donât get me wrong, Rodux is nice and you could create a function to handle this for you. That being said, it would be nice if Roblox could implement something like this:
return {
...state;
ShipSelectionVisible = action.payload;
}
That is to say, it would be nice if we could copy dictionary using {...Dictionary}
, and then altering them by having anything after the ...Dictionary
be an edit to the table, similar to Dictionary[key] = value
. Not only would this be nice for making Rodux more similar to Redux (the main reason I would like to have this added), but it would also allow for easy duplication/editing of duplicated of dictionaries.
This also applies to Arrays. While we can copy arrays using:
local Array2 = unpack({Array1})
It would be nice if this feature could also be implemented for arrays to universalize tables. That is to say, so that both arrays and dictionaries can be copied in a similar way.
Also, according to @sjr04,
Thus, this could be an improvement for copying arrays as well as dictionaries.
All use cases:
- Creating a new table with edited values (useful for state management and other things):
local TableEdited = {...Table, ["EditedKey"] = 1}
- Copying tables:
local TableCopy = {...Table}
- Merging multiple tables into 1 copy:
local Table123 = {...Table1, ...Table2, ...Table3}
- A combination of [1] and [3]:
local TableCombination = {...Table1, ...Table2, ...Table3, ["EditedKey"] = 1}