Giter VIP home page Giter VIP logo

immut's People

Contributors

nidoxs avatar scyfren avatar solarhorizon avatar tracyspells avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

immut's Issues

Create a `Draft` type

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.

Draft values when iterating

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.

Add draft-safe functions for `table.sort` and `table.clear`

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.

Produce returns nested drafts when returning a normal table with nested drafts

This is dangerous for production data as the new state will contain unexpected drafts:
image

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?

Produce does not accept nil, string, number and boolean as base

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

Attempt to call require with invalid arguement(s).

I've been using RoduxUtils recently (very fun to mess around with) and I ran into an error with the Immut library:
1

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 not the same as table.insert

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.