ES Modules *and* a much smaller bundle #224
chriskrycho
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
💥 Changed
The top-level namespace-style export has been removed. If you were relying on the static members to be present when doing
import Maybe from 'true-myth/maybe'
orimport Result from 'true-myth/result';
, you can replace them withimport * as Maybe from 'true-myth/maybe';
orimport * as Result from 'true-myth/result';
. This should make for much better tree-shaking with bundlers like Rollup, which can see “through” a namespace import in a way they cannot with a manually-created namespace object. Where you want to maintain the type and namespace imports, you can do this:In general, though, you should prefer to simply import the named functions instead:
There are no longer separate classes for
Just
,Nothing
,Ok
, andErr
. This substantially reduces the size of the library, and should hopefully improve browsers' ability to optimize code using these, since there is now only one class in each case:Maybe
andResult
. The public API for the classes is unchanged, but if you relied oninstanceof
checks against those classes anywhere, those checks will no longer work.The exported
Variant
types are now frozen, constant objects, not TypeScriptenum
s. This should not break anyone, since the only difference in observable behavior between anenum
and aconst
is the ability to do a “reverse lookup” on anenum
—but since the field names and their values are identical, this just means shipping less, and faster, code.The
isJust
,isNothing
,isOk
, andisErr
methods have been converted to getters. This makes them muchmore immediately useful in contexts where invoking a function is annoying, for any reason—for example, in Ember templates.We no longer publish CommonJS modules, only ES Modules.
Dropped support for Node versions earlier than Node 12 LTS.
Support for versions of TypeScript before 4.0 have been removed, to enable the type-safe re-implementation of
Maybe.all
.The
MaybeShape
andResultShape
interfaces are no longer exported. These were never intended for public reimplementation, and there is accordingly no value in their continuing to be public.A number of aliases (originally designed to make migration from e.g. Folktale easier) have been removed:
cata
: usematch
chain
andflatMap
: useandThen
maybeify
andtransmogrify
: usewrapReturn
unsafelyGet
,unsafeGet
, andunsafelyUnwrap
: use.isJust
/.isOk
then.value
unsafelyGetErr
andunsafelyUnwrapErr
: use.isErr
then.error
getOr
: useunwrapOr
getOrElse
: useunwrapOrElse
fromNullable
andmaybe
:Maybe
and use its static constructorMaybe.of
Maybe.of
of
and alias it as you like⭐ Added
We introduced a new
Maybe.transposeArray
, which is a type-safe, renamed, merged version ofMaybe.tuple
andMaybe.all
which can correctly handle both array and tuple types. To support this change, it now accepts arrays or tuples directly, and the variadic/spread arguments toall
have been replaced with taking an array or tuple directly. Whiletuple
andall
are unchanged, they are also deprecated (see below).Before:
After:
Maybe.transpose
andResult.transpose
: for when you have aMaybe<Result<T, E>>
or aResult<Maybe<T>, E>
and need to invert them.See the docs for further details!
Note: these are standalone functions, not methods, because TypeScript
does not support conditionally supplying a method only for one specific type
parameterization.
🟥 Deprecated
Maybe.tuple
andMaybe.all
are deprecated in favor ofMaybe.arrayTranspose
now correctly handles both arrays and tuples. They will be removed not earlier than 6.0.0 (timeline not decided, but not sooner than when Node 12 LTS reaches end of life on April 30, 2022).Full change list
Maybe.all
implementation by @chriskrycho in [breaking] type-safeMaybe.all
implementation #88*Shape
interface exports by @chriskrycho in [breaking] remove*Shape
interface exports #93any
from the codebase by @chriskrycho in Remove all uses ofany
from the codebase #94engines
, fix authors/contributors by @chriskrycho in Require Node 12 || 14+ inengines
, fix authors/contributors #121ap
docs about currying by @chriskrycho in Correct theap
docs about currying #216transpose
handling by @chriskrycho in Improvetranspose
handling #219New Contributors
Full Changelog: v4.1.1...v5.0.0
This discussion was created from the release ES Modules *and* a much smaller bundle.
Beta Was this translation helpful? Give feedback.
All reactions