Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

option to transform RunicArgs #589

Open
Tracked by #721
harrysolovay opened this issue Feb 16, 2023 · 0 comments
Open
Tracked by #721

option to transform RunicArgs #589

harrysolovay opened this issue Feb 16, 2023 · 0 comments
Assignees
Labels
needs input We need input from the team and/or others request rune

Comments

@harrysolovay
Copy link
Contributor

Let's say that we have the following Rune factory:

function greeting<X>(...args: RunicArgs<X, [name: string, isCool: boolean]>) {
  const [name, isCool] = RunicArgs.resolve(args)
  // ... do something with these Runes
}

What do we do if we want to transform one of the supplied Runes?

function greeting<X>(...args: RunicArgs<X, [name: string, isCool: boolean]>) {
  const name = Rune.resolve(args[0]).map(upperCaseFirst)
  const isCool = Rune.resolve(args[1])
  // ...
}

^ this isn't super clean. One place where this is especially apparent is in the instantiate method of InkMetadataRune, in which we want to fallback to sensible defaults for certain arguments when not provided.

Solution

I propose that RunicArgs.resolve accept an optional second argument, a partial mapping from index to transform.

function greeting<X>(...args: RunicArgs<X, [name: string, isCool: boolean]>) {
  const [name, isCool] = RunicArgs.resolve(args, { 0: upperCaseFirst })
  //
}

In the case of the aforementioned instantiate method:

instantiate<X>(props: RunicArgs<X, InstantiateProps>) {
- const salt = Rune
-   .resolve(props.salt)
-   .unhandle(undefined)
-   .rehandle(undefined, this.salt)
- const value = Rune
-   .resolve(props.value)
-   .unhandle(undefined)
-   .rehandle(undefined, () => Rune.constant(0n))
+ const { salt, value, ... } = RunicArgs.resolve(props, {
+   salt: (v) => v ?? this.salt(),
+   value: (v) => v ?? 0n,
+ })

  // ...
@tjjfvi tjjfvi self-assigned this Feb 20, 2023
@harrysolovay harrysolovay assigned harrysolovay and unassigned tjjfvi Apr 10, 2023
@tjjfvi tjjfvi added request needs input We need input from the team and/or others rune labels Jul 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs input We need input from the team and/or others request rune
Projects
Status: No status
Development

No branches or pull requests

2 participants