Fusion icon indicating copy to clipboard operation
Fusion copied to clipboard

Memoize certain SpecialKeys like OnEvent to allow for easy passthrough.

Open Raild3x opened this issue 2 years ago • 2 comments

Currently, if you want to do passthrough events from one component to another, the current expected way is to use string indices in the props table like so:

local myButtonComponent(props)
   return New "TextButton" {
      [OnEvent "Activated"] = props.Activated
   }
end

myButtonComponent {
   Activated = function()
      print("do thing")
   end
}

However, this can sometimes make it somewhat difficult to have a continuous format for setting things to happen on events.

My proposal is to memoize OnEvent registers so that it is easier to perform actions like the following without having to store the special key return everywhere it is needed. This would make users' codebases much more consistent as they would be able to use the same event formatting for their components as they do when using New if they so wish.

local myButtonComponent(props)
   return New "TextButton" {
      [OnEvent "Activated"] = props[OnEvent "Activated"]
   }
end

myButtonComponent {
   [OnEvent "Activated"] = function()
      print("do thing")
   end
}

Raild3x avatar Jun 20 '23 19:06 Raild3x

This seems like a good change. This should probably also be done for the other special keys that take arguments such as OnChange, Out etc

dphfox avatar Jul 21 '23 12:07 dphfox

This would be a breaking change for those using this special key multiple times in a property table. I don't think that's a dealbreaker though; we could always let these special keys accept array arguments if we really want to support that kind of usage.

dphfox avatar Nov 26 '23 21:11 dphfox

Moving this to an issue #320.

dphfox avatar Apr 15 '24 12:04 dphfox