goldenstein64 / Copy

A Luau-specialized module for copying any value with state.
https://goldenstein64.github.io/Copy
MIT License
0 stars 0 forks source link

Copy.TempTransform #14

Open goldenstein64 opened 3 years ago

goldenstein64 commented 3 years ago

A table that gets flushed after a copy call is finished. We can then make Copy.Transform persistent after every call and make TempTransform use __index on it.

it("has a persistent Transform", function()
  Copy.Transform["value"] = "some other value"

  Copy(nil)

  expect(Copy.Transform["value"]).to.equal("some other value")
end)

it("has a temporary Transform", function()
  Copy.TempTransform["value"] = "some other value"

  Copy(nil)

  expect(Copy.TempTransform["value"]).to.equal(nil)
end)

This would affect every file that uses Transform, since we are changing the behavior of an existing namespace.

goldenstein64 commented 3 years ago

The only problem with this is that metatables are set by default, so the Copy(Copy) idiom wouldn't work. Instead, we can just index both manually over letting metatables deal with it.

goldenstein64 commented 3 years ago

This might also mean we can remove Copy:Flush? If the user wants their mapping removed after a call, they can just store it in TempTransform.

We could also add a flag for auto-storing mappings in Transform instead of TempTransform, or even have a DebugTransform for storing both.