Skip to content

Instantly share code, notes, and snippets.

@Sajjon
Created March 17, 2021 11:58
Show Gist options
  • Save Sajjon/0316cd64becc34d834a612ad0693b2d4 to your computer and use it in GitHub Desktop.
Save Sajjon/0316cd64becc34d834a612ad0693b2d4 to your computer and use it in GitHub Desktop.
Chainable radix type first solution
const create = (): RadixT => {
/// REST OF METHOD OMITTED
// ...
// ...
// ...
/// REST OF METHOD OMITTED
const radix = {
// we forward the full `RadixAPI`, but we also provide some convenience methods based on active account/address.
...api,
// REST OF METHODS OMITTED
connect: (url: URL): RadixT => {
withNodeConnection(of({ url }))
return (undefined as unknown) as RadixT
},
// REST OF METHODS OMITTED
}
const decorateSelf = <I>(
fwd: (partialSelf: RadixT) => (input: I) => RadixT,
): ((input: I) => RadixT) => {
return (input: I): RadixT => {
fwd(radix)(input)
return radix
}
}
return {
...radix,
connect: decorateSelf((r) => r.connect),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment