Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

More reliable detection of Roact elements #20

Closed
AmaranthineCodices opened this issue Jan 27, 2018 · 3 comments · Fixed by #49
Closed

More reliable detection of Roact elements #20

AmaranthineCodices opened this issue Jan 27, 2018 · 3 comments · Fixed by #49

Comments

@AmaranthineCodices
Copy link
Contributor

AmaranthineCodices commented Jan 27, 2018

There should be a more reliable way to check if a table was returned from createElement than checking the isElement key of the resultant table. This is largely futureproofing - I want to guarantee a way to find out whether these tables actually came from createElement, with no false-positives (some other API sets isElement to true for its own reasons, for example) or possibility of breakage (I don't think Roact provides any guarantees about the structure of createElement's return value).

This is probably best accomplished via a symbol - instead of checking isElement, I could check [Roact.Element] or something similar; createElement would set both [Roact.Element] and isElement (for backwards compatibility, if nothing else) in the table it returns.

@LPGhatguy
Copy link
Contributor

I like this idea at face.

One thing to keep in mind is that using a symbol harms the ability to serialize elements to JSON or send them over Roblox events. I don't know how important that is to do, but I can imagine a world where that could be useful!

@AmaranthineCodices
Copy link
Contributor Author

But as it is, serializing elements to JSON/sending them over a (Bindable/Remote)/(Function/Event) will break them in most use cases:

  • Children are stored under [Roact.Children] in the props table
  • Element types are not always serializable (can be tables or functions)

Sending rendered components over some sort of bridge could be useful, but there are already barriers to that.

@LPGhatguy
Copy link
Contributor

Good points! I don't see any other issues with this idea.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants