R
roblox-ts•10mo ago
Unknown User

attempt to modify a readonly table (lapis)

104 Replies
Unknown User
Unknown UserOP•10mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•10mo ago
remap + sift + immut and maybe the spread operator, why not
Unknown User
Unknown UserOP•10mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•10mo ago
noes, immutability means that if you change the values, you need to create a new one with your changes, but if for example, you have PlayerData, and inside you have Settings
interface PlayerData {
SomethingElse: {}
Settings: {}
}
interface PlayerData {
SomethingElse: {}
Settings: {}
}
if you change settings, you'd need to duplicate PlayerData and Settings, but SomethingElse should stay the same, you just add it back as it is in your new PlayerData table so, it's not quite the same as a deep-copy
Unknown User
Unknown UserOP•10mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•10mo ago
what is the code
Unknown User
Unknown UserOP•10mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•10mo ago
yeah this is not gonna work this is a nested table even if you spread it, you are still editing the Slot and then Coins so it's still mutating I might recommend immut for this case
const Document_Data = Document.read();
const New_Data = Immut.produce(Document_Data, (draft) => {
// Award some coins for context:

draft.Slot_1.Coins += 10;
draft.Slot_2.Coins += 10;
draft.Slot_3.Coins += 10;
})
this.Player_Data.set(Player, New_Data );
const Document_Data = Document.read();
const New_Data = Immut.produce(Document_Data, (draft) => {
// Award some coins for context:

draft.Slot_1.Coins += 10;
draft.Slot_2.Coins += 10;
draft.Slot_3.Coins += 10;
})
this.Player_Data.set(Player, New_Data );
wAD
wAD•10mo ago
i wouldn't recommend immut to roblox-ts user
PepeElToro41
PepeElToro41•10mo ago
elaborate
wAD
wAD•10mo ago
immut is horrible
PepeElToro41
PepeElToro41•10mo ago
what how then spread 5 times nested
wAD
wAD•10mo ago
if you use any syntax that generates non-draft save functions inside drafts (spread operators, macros, etc) it will generate code with an UB use remap or spread operator make dispatchers it's not that bad compared to immut
PepeElToro41
PepeElToro41•10mo ago
what is non-draft save functions
wAD
wAD•10mo ago
table.insert, table.clone, etc..
PepeElToro41
PepeElToro41•10mo ago
Im not even gonna talk about macros bruh
wAD
wAD•10mo ago
macros like push generate those functions
PepeElToro41
PepeElToro41•10mo ago
ooohhh
wAD
wAD•10mo ago
so, e.g. you do draft.arr.push(1) and ur cooked
PepeElToro41
PepeElToro41•10mo ago
that is expected it's a skill issue how you'd call it horrible
wAD
wAD•10mo ago
and that is.. HORRIBLE to debug, believe me
PepeElToro41
PepeElToro41•10mo ago
what no never got that problem you just shouldnt do it that's it
wAD
wAD•10mo ago
xD the whole purpose of immut is to produce immutable snaps by state mutations and well.. you say i shouldn't do it šŸ™ why use immut then
PepeElToro41
PepeElToro41•10mo ago
I mean, yeah it's a bad idea to recommend immut for this case, when the guy doesnt know how immutability works yet because nesting table.clones is awful spread operators, remap, sift you name it
wAD
wAD•10mo ago
ok you're recommending using a library for the whole purpose of setting stuff via indexations
PepeElToro41
PepeElToro41•10mo ago
when you need to change something deeper it's a pain
wAD
wAD•10mo ago
you could simply write a utility function that does just that..
PepeElToro41
PepeElToro41•10mo ago
how
wAD
wAD•10mo ago
without the need for something as bug-prone as immut
PepeElToro41
PepeElToro41•10mo ago
explain
wAD
wAD•10mo ago
idk anything like set(state, "tbl1", "tbl2", "tbl3", value) (it's possible to make type-safe)
PepeElToro41
PepeElToro41•10mo ago
is it really that hard to remember not to use array methods?
wAD
wAD•10mo ago
that will clone the objects recursively not array methods spread operator does the same you basically strip any roblox-ts functionality by using immut so why use it
PepeElToro41
PepeElToro41•10mo ago
why would you use spread operators? you already use immut for that
wAD
wAD•10mo ago
patching for example:
produce(state, (draft) => {
state.smh = {
...default, // ur cooked
...patch,
}
})
produce(state, (draft) => {
state.smh = {
...default, // ur cooked
...patch,
}
})
PepeElToro41
PepeElToro41•10mo ago
why would you use immut for patching
wAD
wAD•10mo ago
why are you arguing
PepeElToro41
PepeElToro41•10mo ago
produce(state, (draft) => {
draft.smh = {
...state.smh,
...patch,
}
})
produce(state, (draft) => {
draft.smh = {
...state.smh,
...patch,
}
})
like you just need to know how the library works and then it's very easy to use
wAD
wAD•10mo ago
for what
PepeElToro41
PepeElToro41•10mo ago
you need to internalize it
wAD
wAD•10mo ago
for the purpose of doing a.b.c = 3 that's the only thing u can with this library in roblox-ts
PepeElToro41
PepeElToro41•10mo ago
yes, and editing maps maybe
wAD
wAD•10mo ago
dude, make a utility function
PepeElToro41
PepeElToro41•10mo ago
though you have remap for that
wAD
wAD•10mo ago
remap does just that it's so error-prone, buggy and useless i don't know why one would even consider it
PepeElToro41
PepeElToro41•10mo ago
how that is buggy it just has limitations like everything
wAD
wAD•10mo ago
because if you use a non-draft safe function it won't warn you it will just produce code that does not work it's easily error-prone and it sucks
PepeElToro41
PepeElToro41•10mo ago
you said it sucks, thus you've never used it I use it a lot, never had a problem with it
wAD
wAD•10mo ago
lmao
PepeElToro41
PepeElToro41•10mo ago
how is your opinion more valid here?
wAD
wAD•10mo ago
i used it, and not doing that anymore after debugging why the f*ck my players lose data from time to time for a couple of days straight i'm going to beef with every immut user after what i've been through
PepeElToro41
PepeElToro41•10mo ago
well, you'll eventually get better either with immut, or immutability in general
wAD
wAD•10mo ago
or eventually you'll get better at making design decisions and what to use
PepeElToro41
PepeElToro41•10mo ago
yeah that's the point it's just a tool, it's not gonna magically solve immutability which was probably what you expected
wAD
wAD•10mo ago
though, you still don't understand why are you using it for the sole purpose of doing a.b.c = 3 why not a utility function why use something as error-prone as this
PepeElToro41
PepeElToro41•10mo ago
yes, and relative operators like += and that and for combining a.b.c when c is then a map and so on
wAD
wAD•10mo ago
still not good enough reasoning for me it's funny how you can do certain macros and they work just fine like map.get() or map.set(), obviously, because they don't produce harmful emit but why one would even consider immut for no real benefit why even bother learning all this through pain n ass for what i don't get it
PepeElToro41
PepeElToro41•10mo ago
learning what, it's not that complicated lol you just listed all the edge cases when it fails spread operator, array methods, filter that's all
wAD
wAD•10mo ago
if "edge cases" for you is using default macros that everyone utilizes in their code daily and u think that's ok i don't know what to say to you
PepeElToro41
PepeElToro41•10mo ago
if you need to use filter or the macros you then use sift
wAD
wAD•10mo ago
ok first
PepeElToro41
PepeElToro41•10mo ago
No description
wAD
wAD•10mo ago
why use sift if those macros are immutable in the first place
PepeElToro41
PepeElToro41•10mo ago
its not like spread operators are easier to read tbh like, this is harder to reason with and this is just a single property
wAD
wAD•10mo ago
i'm not opposed to using sift
PepeElToro41
PepeElToro41•10mo ago
I didnt even know that when you marked an array as readonly, the macros were still there, just with an immutable version
wAD
wAD•10mo ago
i'm opposed to using immut
PepeElToro41
PepeElToro41•10mo ago
that's so bizzarre tbh
wAD
wAD•10mo ago
?? wtf macros are immutable even with regular arrays i don't know what you're saying
PepeElToro41
PepeElToro41•10mo ago
oh ya they have some it has move which is weird anyway, I still prefer to use Sift with immutable arrays, doesnt matter if there is a macro that works with immutable data it's just weird, and I dont even mark my interfaces with readonly plus, modifying accidentally an immutable state is a bug harder to find, than trying to manipulate the draft the latter is a lot more obvious
wAD
wAD•10mo ago
this argument is invalid it's your fault for not typing your state as immutable properly
PepeElToro41
PepeElToro41•10mo ago
I just have immutability already internalized even my thoughs are immutable
wAD
wAD•10mo ago
use a filter macro and stop gaslighting yourself into immut being good i did that a while ago, and i'm happy ever since
PepeElToro41
PepeElToro41•10mo ago
well, Im also happy ever since I used immut :DD
wAD
wAD•10mo ago
ur reality isn't real u live in the matrix it's an illusion of happiness :D
PepeElToro41
PepeElToro41•10mo ago
just like immut it lies to you
wAD
wAD•10mo ago
immut's whole point is to lie to you
PepeElToro41
PepeElToro41•10mo ago
you just need to be better than immut faster
wAD
wAD•10mo ago
it gaslights you into thinking ur state can be mutated safely
PepeElToro41
PepeElToro41•10mo ago
but you secretly know that's not true that's why it cant trick you
wAD
wAD•10mo ago
yes, but evil nonetheless a lie is a sin immut is made and distributed by devil
Unknown User
Unknown UserOP•10mo ago
Message Not Public
Sign In & Join Server To View
wAD
wAD•10mo ago
it does work but it doesn't help the problem
Unknown User
Unknown UserOP•10mo ago
Message Not Public
Sign In & Join Server To View
wAD
wAD•10mo ago
yes and that's dogshit because it doesn't match ts api
Unknown User
Unknown UserOP•10mo ago
Message Not Public
Sign In & Join Server To View
wAD
wAD•10mo ago
it doesn't match ts api (which is array.push) and it doesn't help the problem in the first place the problem is it being error-prone
Unknown User
Unknown UserOP•10mo ago
Message Not Public
Sign In & Join Server To View
wAD
wAD•10mo ago
alternative: set(obj, "field", "something", 2)
Unknown User
Unknown UserOP•10mo ago
Message Not Public
Sign In & Join Server To View
wAD
wAD•10mo ago
no, but i'm pretty sure it's possible to make it type-safe, lemme try to make that up ok i half-assed this by taking replica-service types but u get the point
roblox-ts
roblox-ts•10mo ago
Playground link
Posted by <@343061601831616522>
wAD
wAD•10mo ago
it could probably be a separate package if someone wanted to
Unknown User
Unknown UserOP•10mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•10mo ago
wtf huh I think you should learn how to work with immutable data, or, do something else, otherwise its gonna be a pain lapis can be worked mutably but the roblox-ts types are still immutable
Unknown User
Unknown UserOP•10mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•10mo ago
No description
PepeElToro41
PepeElToro41•10mo ago
No description
PepeElToro41
PepeElToro41•10mo ago
this how you would with Sift sift has a Sift.Dictionary the other one is with the spread operator
const newVal = {
...oldVal,
Key1: {
...oldVal.Key1
Key2: {
...oldVal.Key2
Key3: // change here
}
}
}
const newVal = {
...oldVal,
Key1: {
...oldVal.Key1
Key2: {
...oldVal.Key2
Key3: // change here
}
}
}
Unknown User
Unknown UserOP•10mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•10mo ago
seems correct
PepeElToro41
PepeElToro41•10mo ago
No description
PepeElToro41
PepeElToro41•10mo ago
with immut you could just edit it as it is but I'd agree with wad it's not a magical solution and if you are not careful, it could be a footgun simulator
roblox-ts
roblox-ts•10mo ago
Playground link
Posted by <@342788489831645184>

Did you find this page helpful?