cassiozen / useStateMachine

The <1 kb state machine hook for React
MIT License
2.38k stars 47 forks source link

feat(dx): instantiate all boundary types #76

Closed devanshj closed 2 years ago

devanshj commented 3 years ago

I was writing the documentation and realized the errors and quickinfo are horrible, I mean I knew it previously and I tried this before but apparently it did not work or I was doing it wrong, revisited it and now it works.

Basically typescript skips instantiating type for performance reasons and just shows it's name, but with A.Instantiate we force typescript to compute and instantiate it.

It comes with some cost that typescript has to do more work and in worst case it might result in "instantiation is too deep or possibly infinite" but I think that won't happen. Even if it happens we'll basically revert this and publish a patch, as it has got nothing to do with code only error messages and quickinfo.

The boundary positions are namely: state, send, effectParameter, effectCleanupParameter, guardParameter.

A few examples of the change
Before: ![image](https://user-images.githubusercontent.com/30295578/128439194-05d8d39a-d031-44ec-9f9d-f9d50a11877b.png) After: ![image](https://user-images.githubusercontent.com/30295578/128439244-d047b46b-9def-438d-a375-a3d204dfcdbd.png) Before: ![image](https://user-images.githubusercontent.com/30295578/128439833-b41ab782-3f5b-4e3c-baaa-03b545bd94bf.png) After: ![image](https://user-images.githubusercontent.com/30295578/128439895-7d3e5f0a-a596-4c42-aa14-3faea7bfb310.png) Before: ![image](https://user-images.githubusercontent.com/30295578/128439454-3ccd68b4-7610-48f6-8711-9f8466a5a143.png) After: ![image](https://user-images.githubusercontent.com/30295578/128439484-709c652b-59ad-47b4-ae5c-ae3fc1b8816b.png) Before: ![image](https://user-images.githubusercontent.com/30295578/128439547-d4e38003-aa29-49da-95fa-69ebb0ee6709.png) After: ![image](https://user-images.githubusercontent.com/30295578/128439687-9bf78a33-8905-4f38-b6f3-e4fef0fa6a19.png)
devanshj commented 3 years ago

don't instantiate context, event and builtins

Meaning we preserve names for these things. For example, in the following case we preserve the name of context Something and not instantiate it to it's definition { foo: string }

Before: image

After: image

devanshj commented 2 years ago

@cassiozen could you publish a version with this so that I can see what types are shown on hover when I resume writing the documentation?

cassiozen commented 2 years ago

Done!