Consider using SolidJS
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 389
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
Description
Currently Neuroglancer does not rely on any third-party UI framework, and instead essentially has its own, with the following properties:
- DOM nodes are created and updated manually, in a way that is probably close to optimal in terms of efficiency, but is very cumbersome.
- Updates are handled in a "reactive" way using the `Signal`, `WatchableValue`, and similar classes, which require manually registering/unregistering callbacks, which is also cumbersome and error prone.
- The need to manually register/unregister callbacks contributes to the need for pervasive manual reference counting throughout the Neuroglancer codebase, which is also cumbersome and error prone.
- The lack of a mechanism to "batch" updates to `WatchableValue` and similar types, and defer signals until the entire batch completes, requires various workarounds to avoid issues in some cases.
It appears that SolidJS is a promising alternative. SolidJS provides both a "reactive state management" library, which would replace the Signal/WatchableValue mechanism in Neuroglancer, and also a UI library built on top of that.
The SolidJS reactive state management library, which is very similar to MobX, avoids the need to manually register/unregister callbacks by instead tracking when the value contained in SolidJS's equivalent of Neuroglancer's `WatchableValue` (called a `Signal` in SolidJS) in order to infer dependencies automatically. Essentially it re-registers the necessary callbacks as one-time callbacks on each access, but does it a very efficient way.
The UI library is one the most efficient JavaScript UI libraries available. It allows UI "components" to be defined with JSX, similar to React, but avoids the overhead of a virtual DOM and instead relies on a compilation process via a babel plugin that directly generates the code for creating and updating the DOM nodes. It appears that the resultant code is likely fairly similar to what is currently done manually in Neuroglancer.
Migrating all of Neuroglancer at once would be impractical, but because the SolidJS model is quite similar to how Neuroglancer already works, I expect it should be possible to migrate individual components at a time. Neuroglancer WatchableValue objects can be mapped to SolidJS signals, and vice versa, and SolidJS UI components can similarly interoperate with Neuroglancer UI components in a straightforward way.
Contributor guide
Assessment
This issue has not been assessed yet.