Skip to content

v0.11.0

Choose a tag to compare

@github-actions github-actions released this 28 Oct 06:27
· 128 commits to main since this release
Immutable release. Only release title and notes can be modified.
8ee18e5

This release reworks the companion API. Code written for 0.10 needs the changes below.

Upgrading

  • Import Enum, Trait, Tag and Otherwise from valof. valof/experimental is removed (#98).

  • End every companion chain with .build(), for Val, Enum and Trait (#86):

    const User = Val.companion<User>().build();
  • Replace Val.sealer<User>() with Val.companion<User>(), and User(payload) with
    User.seal(payload) (#82). A companion is not callable. Replace Enum.sealer the same way.

  • Pass impl and implTrait a function that returns the members (#92). The function receives
    seal, patch and create when implCreate registered one. A member that calls them needs no
    return-type annotation:

    // before
    .impl({ renamed: (u, name: string): User => User.patch(u, { name }) })
    // after
    .impl(({ patch }) => ({ renamed: (u, name: string) => patch(u, { name }) }))
  • Replace .fixed<"id">() with a type argument: Val.companion<User, [Unpatchable<"id">]>() (#83).

  • Replace pipe(u, User.greet()) with pipe(u, User.greet), where the member's only parameter is
    the value. User.greet() is now a type error (#97).

  • Replace Shape.__valof_tag with Shape[Tag] (#90).

  • Remove detached-impl from your valof-lint config (#86).

Enums

Write each variant's steps in the chain after the variant's name, as .Click.implSeal, and declare
a renamed tag with .tag("kind") (#87). implVariant and the companion("kind") argument are
removed:

// before
Enum.companion<Event>("kind")
  .implSeal(checkId)
  .implVariant("Click", (variant) => variant.implSeal(checkClick).impl({ moved }))
  .build();

// after
Enum.companion<Event>()
  .tag("kind")
  .Click.implSeal(checkClick)
  .Click.impl(() => ({ moved }))
  .implSeal(checkId)
  .build();

Warning

An implSeal on the enum, not on a variant, now runs only in Event.seal.
Event.Click.seal, Event.Click.create and Event.Click.patch skip it. Where a check must run
on every variant, move it into each variant's implSeal.

Replace Shape.Circle({ r: 2 }) with Shape.Circle.create({ r: 2 }). A variant's seal expects
the payload including the tag: Shape.Circle.seal({ _tag: "Circle", r: 2 }).

What's Changed

💥 Breaking

  • feat!: drop .sealer, make .seal the only way in, and .companion offers default .seal by @jo16oh in #82
  • feat!: replace .fixed with Unpatchable, and add PrivateSeal, as companion type arguments by @jo16oh in #83
  • feat!: close every companion chain with .build() by @jo16oh in #86
  • feat!: rebuild the Enum API as one chain by @jo16oh in #87
  • feat!: turn the __valof_ keys into symbols by @jo16oh in #90
  • feat!: take the members of impl and implTrait through a function by @jo16oh in #92
  • feat!: drop the value-last form from a member taking only the value by @jo16oh in #97
  • feat!: drop valof/experimental, and export Enum and Trait from the root by @jo16oh in #98

✨ Features

  • feat: add _ to match for the variants without a handler of their own by @jo16oh in #80
  • feat: allow any variant name and a then member by @jo16oh in #91
  • feat: add implAssoc for members that do not take the value by @jo16oh in #95

🔧 Fixes

  • fix: let a consumer emit declarations for an exported companion by @jo16oh in #88
  • fix: throw in development on a member hiding a default or a rest parameter by @jo16oh in #102

⚡ Performance

  • perf: share the builder steps between Val and Enum by @jo16oh in #93
  • perf: wrap what a step's function receives in NoInfer by @jo16oh in #94

📝 Docs

  • docs: state the TypeScript requirement in the README, and rewrite the enums chapter by @jo16oh in #96
  • docs: merge the README examples into one by @jo16oh in #99
  • docs: fix factual errors, and proofread the book and the hovers by @jo16oh in #100
  • docs: restructure the book by @jo16oh in #101

Full Changelog: v0.10.0...v0.11.0