capi icon indicating copy to clipboard operation
capi copied to clipboard

initializing runes from constants

Open harrysolovay opened this issue 2 years ago • 3 comments

Currently, we do the following:

const rune = Rune.constant(theValue).into(TheRuneSubclassCtor)

Let's consider a larger example.

const denoFsHost = Rune
  .constant({
    readFile(filePath: string) {
      return Deno.readFile(filePath)
    },
    // more ...
  })
  .into(FsHostRune)

If we rework the design as follows...

  • the parameter types can be inferred
  • we need not import Rune
  • confusion about the meaning of Rune.constant is avoided entirely (#569)
  • the code is more legible
const denoFsHost = FsHostRune.of({
  readFile(filePath) {
    return Deno.readFile(filePath)
  },
  // more ...
})

harrysolovay avatar Feb 22 '23 04:02 harrysolovay

This is in line with my suggestion from #569:

I think Rune.resolve should be renamed to Rune.from. Then, it can be redesigned to work with subclasses, such that FooRune.from(runic, ...ctorArgs) is a shorthand for Rune.resolve(runic).into(FooRune, ...ctorArgs) (though I would need to confirm that the typing is fine).

tjjfvi avatar Feb 22 '23 13:02 tjjfvi

Blocked on #517

EDIT

Indeed @tjjfvi, I commented on the wrong issue. Ignore.

harrysolovay avatar Feb 27 '23 18:02 harrysolovay

@harrysolovay I think you commented on the wrong issue?

tjjfvi avatar Feb 27 '23 20:02 tjjfvi