Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better types with branding #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ddurschlag
Copy link

This change adds a protected brand to what is returned by observable, and removes it from raw. This allows tracking of what is observable by the type system.

The existing code used proxies, which are transparent: there is no way to distinguish a proxy from a non-proxy. This leads to awkward code that takes a parameter, observes that parameter, and really really hopes that parameter was observable. The alternative is to do a runtime check for obervable-ness, which has both performance and legibility implications.

I've used this a little so far and its worked well, but it may have issues with very complex types I haven't seen yet. It also does impose a requirement that observed types cannot have a property called __OBSERVABLE_NOMINAL_BRAND. This seemed an acceptable trade-off.

Future work could be to turn isObservable into a typeguard from T to Observable.

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

Successfully merging this pull request may close these issues.

1 participant