Description
The behavior work is creating a lot of related types, functions, and constants that extending code will need access to—things to define behaviors and extensions, pre-defined behaviors, the types of those behaviors and extensions, etc.
I'm opening this issue as a place to organize my thoughts and invite discussion.
Namespacing
So far, I've been leaning towards using as flat as possible a namespace within each package—everything goes into the top exports, except for the occasional static method that reads better when tacked onto a class.
I'm a bit concerned about our namespaces (in the state and view packages), and thus our docs, becoming an unclear mess when they are littered with too many individual exports. Also, names in such a namespace tend to become long (defineViewBehavior
).
One approach to avoiding this would be to introduce namespaces inside the packages, within classes or, if the concept isn't a class, in a TypeScript namespace named after the relevant type. So you'd get ViewBehavior.define
instead. The disadvantages of that are:
-
Such names can no longer be imported conveniently with an
import
statement, and thus if you need such values or types often in a piece of code, you'll have to either define it locally with aconst
ortype
declaration, or repeatViewBehavior.
a lot. -
Rollup and other bundlers probably won't collapse such bindings to local identifiers, so they leave behind an actual object access (more bytes) in the bundled code.
-
Depending on how clever a tree shaker is, it might not be able to tree-shake the junk that TypeScript compiles namespaces to (iifes assigning to an object they get as argument).
The other approach would be to make sure our doc generating tool supports organizing bindings under sections (as builddocs does for the ProseMirror sources via the src/README.md
mechanism), and hope that's enough to keep the docs clear.
Contextual naming
Instead of calling something ViewBehavior
or even EditorView
, we could create names in the context of the package that they belong to (Behavior
/ View
) to make them less verbose. The main problem with this is name clashes (whenever you need both view behavior and state behavior, you'll have to import Behavior as ViewBehavior
etc to disambiguate, and names like Selection
clash with definitions from the dom types, which is even more annoying).
The current situation is a bit messy (I'm EditorView
because View
seems too minimal, but I am using ViewBehavior
because EditorViewBehavior
is just too much).
So naming remains hard. I guess we can continue just winging it, and figuring out the least problematic approach case-by-base, but it'd be nice if we could agree on some kind of basic stylistic choices. Thoughts?