Migrating from 0.x
- Part
- Background
Hyrax 1.0 is a rewrite of the 0.x package (@gpsign/hyrax), with the package name @gabreusi/hyrax. The API is smaller, has named exports only, and fixes a number of bugs, some of which changed behaviour. This page lists what became of everything.
The map
| 0.x | 1.0 |
|---|---|
Hyrax (the default object), HyraxDOM, HyraxString, HyraxNumber, utils | Removed. Use named imports |
map(x, inMin, inMax, outMin, outMax) | remap(x, [inMin, inMax], [outMin, outMax]) |
percent(v, hundred, zero) | ratio(v, max, min) |
clamp with numeric strings | clamp takes only number |
Random.number(min, max, digits) | random.int(min, max) or random.float(min, max) |
Random.uuid(n) | random.id(n) (the new uuid() is a real version 4 UUID) |
Random.boolean(75) | random.boolean(0.75) |
a static Random.<method> | the random instance, or new Random(seed); for tokens, Random.secure() |
new StringBuilder(true) | new StringBuilder({ unique: true }) |
StringBuilder.get(delim) | build(separator) |
Suspend.addListener(cb, once) | new Suspend(options).on(cb, { once }) |
nvl | coalesce |
Nullun<T> | Maybe<T> |
toNumber("2em") (needed a DOM) | toPixels("2em") in /dom |
getPropertySize | toPixels in /dom |
useHTMLEventListener(ref, type, fn, deps) | useEventListener(ref, type, fn), with no dependency array |
useUpdate | useForceUpdate |
useInterval(..., { initial, stateless }) | useInterval(..., { autoStart }) (isRunning is always state) |
BlurListener, ChildrenRefs, useChildrenRefs | useClickOutside, or onClickOutside outside React |
hx(Component) with shortcut props such as width | hx(Component) only adds rendered and transient: use style, or hx.<tag> |
length, useAudioRecorder, getBoundingClientRect, getCSSProperties | Removed |
Behaviour that changed on purpose
These are bugs in 0.x that were fixed, so code that relied on them will notice.
Numbers
clamp(50, 5, 100)returned the wrong number (its arguments were sorted as text). Now it is50.remapreturnsoutMinfor an input range of zero width, where 0.x divided by zero and gaveNaNorInfinity.ratioreturns0for an empty range.percentreturned a fraction. The new name,ratio, says so.
Strings and random
- The case functions kept no digits, and now they do (
"foo2bar"stays"foo2bar"), and they treat acronyms as one word. Randomuses rejection sampling, so it has no modulo bias, andboolean(50)is an error and not "always true".StringBuilderapplies a prefix once, anduniqueandremovecompare the final text. In 0.x,append("x", "a-")followed byremove("x")removed nothing.aliasno longer finds inherited names such astoString, and forwardsinanddelete.
Suspend
- It is an instance, and not a global. A first listener added ten minutes after the page loaded used to fire "suspended for 600 s"; the clock now starts when the timer does.
- It no longer touches
window, and in Node the timer does not keep the process alive.
DOM
getPropertySizemeasured withposition: fixed, so a percentage was relative to the window and not to the container.toPixelsmeasures inside the element you give it.- A missing variable used to measure as the width of the parent.
toPixelsreturnsNaN. useHTMLEventListenerremoved a listener without its capture flag, so a capture listener was never removed.BlurListenerdecided "inside" by walkingparentElement, which does not cross Shadow DOM and does not see a node that was removed.onClickOutsideuses the event'scomposedPath().
React
hxno longer usesReact.memo(it protected nothing, becausestyleandchildrenchange on every render), usesforwardRef, has adisplayName, and ignoressymbolkeys. Where a shortcut name is a real attribute (<hx.canvas width>) the prop is passed through.hx(Component)used to consume shortcut names such aswidtheven when the component declared them itself.Portalno longer readsdocument.bodywhile rendering, so it works in server rendering.