solarhorizon / immut Goto Github PK
View Code? Open in Web Editor NEWImmutable data library
Home Page: https://solarhorizon.github.io/immut/
License: MIT License
Immutable data library
Home Page: https://solarhorizon.github.io/immut/
License: MIT License
To match redux toolkit's behavior, action types should look like sliceName/actionName
Immer has a nothing
symbol that allows the new state to become undefined (see immer docs). It would be useful to have it here in immut as well.
Currently, Drafts are cast to the type of the table they are based on. This makes autocompletion work nicely, but it's not correct. There should probably be a Draft
type wrapped around whatever the user passes in.
I will have to explore if this is even possible in Luau right now. Working with metatable types has been a struggle so far.
I have a table draft with nested tables and when I iterate through it, the values should be drafted as I may modify them. Currently, they are not drafted and any modifications to them mutates the original state.
Similar to why there is Immut.insert and Immut.remove, using table.sort and table.clear does not invoke the __index and __newindex metamethods, making them not draft-safe. It would be useful to have draft-safe functions for table.sort and table.clear.
This is dangerous for production data as the new state will contain unexpected drafts:
No specific use-case, I was just playing around and tried this out. Usage of roblox-ts will make this issue more likely due to array methods that return new arrays e.g.
state.nest.find((nest) => nest.value === 0).value += 1
return state.filter((nest) => nest.value !== 0); // will return a normal table containing drafts
The fix I thought of was to finalize drafts inside normal table if normal table is returned (see my attempted fix: master...Scyfren:immut:fix-non-draft-not-finalized).
However I'm unsure if that's a good fix. Should this just be accepted as intended behavior?
The following will error:
produce("", function(draft)
return "abc"
end)
produce(1, function(draft)
return 2
end)
produce(true, function(draft)
return false
end)
produce(nil, function(draft)
return nil
end)
ReplicatedStorage.rbxts_include.node_modules.@rbxts.immut.src.Draft:32: Drafts can only be based off of tables. Got string
Tried to implement a fix: master...Scyfren:immut:fix-produce-to-accept-non-draftable-base
But my fix allows tables with metatables. Unsure how exactly @SolarHorizon wants to handle allowing of nil, string, number, boolean as base, so will leave it to him to fix
EDIT: Actually, my fix doesn't allow tables with metatables as Draft.new() would throw an error. Will still leave it to SolarHorizon though as I'm unsure if my fix is the approach he would take
I've been using RoduxUtils recently (very fun to mess around with) and I ran into an error with the Immut library:
In lines 14-15 of the init.lua, you had something like this:
local remove = require(script.table.remove)
local insert = require(script.table.remove)
For some reason, the table
folder doesn't exist when I play test my game.
(also both remove
& insert
return the same require)
Draft.insert only reflects the 3 parameter definition of table.insert (function insert(t: table, pos: number, value: any)). It would be a lot nicer to work with Draft.insert if it also had the option for the 2 parameter definition of table.insert (function insert(t: table, value: any)).
Current usage:
Draft.insert(tbl, #tbl + 1, data)
Desired usage:
Draft.insert(tbl, data)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.