nettybun / haptic

Explicit reactive web rendering in TSX with no compiler, no virtual DOM, and no magic. 1.6kb min+gz.
MIT License
79 stars 2 forks source link

Improve naming of properties and exports in Haptic Wire #8

Closed nettybun closed 3 years ago

nettybun commented 3 years ago

Related to #5. Naming is very hard. Naming is also an important part of the library for many debugging reasons (see #5). I want the names of exports to make sense since they're two sides to the same coin and don't do much alone. I had previously chosen WireSignal & WireReactor to show that they're related by a prefix. This was really long for inline JSX so wS/wR was used too. This wasn't great for readability (also commented in #2) and therefore also wasn't very explicit/meaningful. I also learned that people hear "reactor" and think of nuclear reactors, which is surprising and not what I meant.

The names need to fit together, but they also need to be short. A replacement for "reactor" needs to fit nicely for inlined JSX. In #5 I proposed "sub". Other attempts were: (repeat) rep(), (subscribe) sub(), link(), (connect) con(), anew(), (socket) sock(), sync(), ...

I've picked WireSignal and WireCore right now.

Here are the new exports of Haptic Wire:

export {
  signal,
  signalsFrom,
  core,
  coreReset,
  corePause,
  coreAdopt,
  transaction,
  v$
};

TypeScript will still show the functions created by signal()/signalsFrom() and core() as WireSignal and WireCore respectively, which is good since I want them to be related by a prefix. There's a new export, signal, which creates an unnamed signal. The original form of signal creation using an object (which encourages/simplifies naming to help debugging) is now signalsFrom. I also changed "adopt" to show that it's to be used for cores. Internally, some FSM names were changed and the function properties on signals and cores now have nice closer-to-full-length names such as "signalRS" rather than "sS"; JSDoc describes these.

This hurts bundle size (see commits) but I'm trying to care about that less.

nettybun commented 3 years ago

Dropped signalsFrom() for signal.object(). This way there's only one export.