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

Type Checking API #227

Open
LPGhatguy opened this issue Aug 7, 2019 · 1 comment · May be fixed by #230
Open

Type Checking API #227

LPGhatguy opened this issue Aug 7, 2019 · 1 comment · May be fixed by #230
Assignees
Labels
feature: planned A feature that's been accepted into the project's roadmap.

Comments

@LPGhatguy
Copy link
Contributor

It'd be useful to have a method to determine the type of objects created by Roact in order to validate them more rigorously.

We can expose this through a feature we already have internally, Type. The public API would be:

  • Roact.typeOf(object) -> RoactType | nil
  • Roact.Type, an enum with these variants, taken from Type.lua:
    • Binding
    • Element
    • HostChangeEvent
    • HostEvent
    • StatefulComponentClass
    • StatefulComponentInstance
    • VirtualNode -- objects of this type aren't currently exposed to users
    • VirtualTree

We should be careful not to expose the actual Type symbol that we use as a key for these types, which would allow users to impersonate Roact instances.

Alternatively, we could have this function return strings instead of enum variants. This would let us keep the set of types we expose open (potentially aiding modularity), but introduce the potential for typos from our users. This has precedent in Lua's type and Roblox's typeof functions.

@LPGhatguy LPGhatguy added the feature: planned A feature that's been accepted into the project's roadmap. label Aug 7, 2019
@MisterUncloaked MisterUncloaked self-assigned this Aug 8, 2019
MisterUncloaked added a commit to MisterUncloaked/roact that referenced this issue Aug 9, 2019
Added a public API for type checking in Roact

- Added nameOf function to Type to lookup the string name for any Type
- Added TypeMirror module which exposes a subset of types in Type without exposing the internal Roact symbols
- Added Roact.Type and Roact.typeOf to expose a type checking API for external use
@MisterUncloaked
Copy link
Contributor

I made some good progress on this today and will have a PR up tomorrow. I'm just working on documentation at this point.

This was referenced Aug 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature: planned A feature that's been accepted into the project's roadmap.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants