Repository navigation
v0.11.0
This release reworks the companion API. Code written for 0.10 needs the changes below.
Upgrading
-
Import
Enum,Trait,TagandOtherwisefromvalof.valof/experimentalis removed (#98). -
End every companion chain with
.build(), forVal,EnumandTrait(#86):const User = Val.companion<User>().build();
-
Replace
Val.sealer<User>()withVal.companion<User>(), andUser(payload)with
User.seal(payload)(#82). A companion is not callable. ReplaceEnum.sealerthe same way. -
Pass
implandimplTraita function that returns the members (#92). The function receives
seal,patchandcreatewhenimplCreateregistered 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())withpipe(u, User.greet), where the member's only parameter is
the value.User.greet()is now a type error (#97). -
Replace
Shape.__valof_tagwithShape[Tag](#90). -
Remove
detached-implfrom 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.sealthe only way in, and.companionoffers default.sealby @jo16oh in #82 - feat!: replace
.fixedwithUnpatchable, and addPrivateSeal, 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
_tomatchfor the variants without a handler of their own by @jo16oh in #80 - feat: allow any variant name and a
thenmember 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