Skip to content

Commit 0b70210

Browse files
committed
Fix bug due to mutating table while iterating
1 parent 0abecbf commit 0b70210

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ You can download the latest release of froact as a rbxm file from https://github
77

88
Froact can be added to your project via [Wally](https://wally.run/) by adding this line under dependencies.
99
```toml
10-
froact = "fewkz/froact@0.1.1"
10+
froact = "fewkz/froact@0.1.3"
1111
```
1212

1313
## How to use

froactful.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,21 @@ function froact.configure<Hooks>(config: {
197197
if config.defaultProperties then config.defaultProperties else {}
198198
)
199199
local function apply(props: any)
200+
local toRemove = {}
200201
for name, value in props do
201202
if typeof(name) == "string" then
202203
if name:sub(1, 2) == "on" then
203204
props[(config.Roact.Event :: any)[name:sub(3)]] = value
204-
props[name] = nil
205+
toRemove[name] = true
205206
elseif name:sub(1, 4) == "bind" then
206207
props[(config.Roact.Change :: any)[name:sub(5)]] = value
207-
props[name] = nil
208+
toRemove[name] = true
208209
end
209210
end
210211
end
212+
for name, _ in toRemove do
213+
props[name] = nil
214+
end
211215
if props.ref then
212216
props[config.Roact.Ref] = props.ref
213217
props.ref = nil

generate.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,17 +492,21 @@ def count_references(klass):
492492
body_lines.append(
493493
"""\
494494
\tlocal function apply(props: any)
495+
\t\tlocal toRemove = {}
495496
\t\tfor name, value in props do
496497
\t\t\tif typeof(name) == "string" then
497498
\t\t\t\tif name:sub(1, 2) == "on" then
498499
\t\t\t\t\tprops[(config.Roact.Event :: any)[name:sub(3)]] = value
499-
\t\t\t\t\tprops[name] = nil
500+
\t\t\t\t\ttoRemove[name] = true
500501
\t\t\t\telseif name:sub(1, 4) == "bind" then
501502
\t\t\t\t\tprops[(config.Roact.Change :: any)[name:sub(5)]] = value
502-
\t\t\t\t\tprops[name] = nil
503+
\t\t\t\t\ttoRemove[name] = true
503504
\t\t\t\tend
504505
\t\t\tend
505506
\t\tend
507+
\t\tfor name, _ in toRemove do
508+
\t\t\tprops[name] = nil
509+
\t\tend
506510
\t\tif props.ref then
507511
\t\t\tprops[config.Roact.Ref] = props.ref
508512
\t\t\tprops.ref = nil

wally.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "fewkz/froact"
33
description = " Wrapper around Roact & Roact Hooks to simplify UI development"
4-
version = "0.1.1"
4+
version = "0.1.3"
55
license = "MIT"
66
registry = "https://github.com/UpliftGames/wally-index"
77
realm = "shared"

0 commit comments

Comments
 (0)