Skip to content

Commit

Permalink
Fix bug due to mutating table while iterating [2]
Browse files Browse the repository at this point in the history
  • Loading branch information
fewkz committed Sep 23, 2022
1 parent 0b70210 commit 5817db0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ You can download the latest release of froact as a rbxm file from https://github

Froact can be added to your project via [Wally](https://wally.run/) by adding this line under dependencies.
```toml
froact = "fewkz/[email protected].3"
froact = "fewkz/[email protected].4"
```

## How to use
Expand Down
8 changes: 6 additions & 2 deletions froactful.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,21 @@ function froact.configure<Hooks>(config: {
)
local function apply(props: any)
local toRemove = {}
local toAdd = {}
for name, value in props do
if typeof(name) == "string" then
if name:sub(1, 2) == "on" then
props[(config.Roact.Event :: any)[name:sub(3)]] = value
toAdd[(config.Roact.Event :: any)[name:sub(3)]] = value
toRemove[name] = true
elseif name:sub(1, 4) == "bind" then
props[(config.Roact.Change :: any)[name:sub(5)]] = value
toAdd[(config.Roact.Change :: any)[name:sub(5)]] = value
toRemove[name] = true
end
end
end
for name, value in toAdd do
props[name] = value
end
for name, _ in toRemove do
props[name] = nil
end
Expand Down
8 changes: 6 additions & 2 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,21 @@ def count_references(klass):
"""\
\tlocal function apply(props: any)
\t\tlocal toRemove = {}
\t\tlocal toAdd = {}
\t\tfor name, value in props do
\t\t\tif typeof(name) == "string" then
\t\t\t\tif name:sub(1, 2) == "on" then
\t\t\t\t\tprops[(config.Roact.Event :: any)[name:sub(3)]] = value
\t\t\t\t\ttoAdd[(config.Roact.Event :: any)[name:sub(3)]] = value
\t\t\t\t\ttoRemove[name] = true
\t\t\t\telseif name:sub(1, 4) == "bind" then
\t\t\t\t\tprops[(config.Roact.Change :: any)[name:sub(5)]] = value
\t\t\t\t\ttoAdd[(config.Roact.Change :: any)[name:sub(5)]] = value
\t\t\t\t\ttoRemove[name] = true
\t\t\t\tend
\t\t\tend
\t\tend
\t\tfor name, value in toAdd do
\t\t\tprops[name] = value
\t\tend
\t\tfor name, _ in toRemove do
\t\t\tprops[name] = nil
\t\tend
Expand Down
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fewkz/froact"
description = " Wrapper around Roact & Roact Hooks to simplify UI development"
version = "0.1.3"
version = "0.1.4"
license = "MIT"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
Expand Down

0 comments on commit 5817db0

Please sign in to comment.