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

rune: add support for DI via env #517

Open
Tracked by #721
tjjfvi opened this issue Jan 25, 2023 · 3 comments
Open
Tracked by #721

rune: add support for DI via env #517

tjjfvi opened this issue Jan 25, 2023 · 3 comments
Assignees

Comments

@tjjfvi
Copy link
Contributor

tjjfvi commented Jan 25, 2023

Like #516, I think this should happen outside of #454.

@tjjfvi tjjfvi self-assigned this Jan 25, 2023
This was referenced Jan 30, 2023
This was referenced Feb 12, 2023
@harrysolovay
Copy link
Contributor

For context: this will serve as a means of DI in Runes (for instance, injecting a custom logger, or runtime client)... perhaps a rune-ified paritytech/zones#20 (although may have a very different API, we shall see).

@harrysolovay
Copy link
Contributor

Perhaps our DI approach can satisfy the use case of #706: consumers of pattern libs could hook into parts of the pattern's execution at pattern-dev-defined waypoints.

@harrysolovay
Copy link
Contributor

harrysolovay commented Apr 1, 2023

Idea for this feature:

// 1. Define a key, to be used for applying to the placeholder.
const userId = Symbol()

// 2. Define a rune containing a placeholder(s) (the output of the `Rune.env` factory).
const free = System.Account
  .value(Rune.env(userId))
  .unhandle(undefined)
  .access("data", "free")

// 3. Apply a value/rune to the placeholder at any point in the tree.
const alexaFree = free.apply(userId, alexa.publicKey)

It's worth noting that in step 2, the type of Rune.env is inferred from its context (in the 1st param position of the value method call). Typing this could prove convoluted, as we'd need to ensure that the same key cannot placehold items of different types.

This feature will be especially useful for the injection of custom lifecycle handlers into patterns. Consider the virtual multisig pattern: currently, this pattern is a black box. It creates many pure proxies, submits existential deposits, performs ownership swaps and more. In the future, this pattern can expose symbols to be used for (optionally) applying callbacks to hook placeholders.

await VirtualMultisigRune
  .deployment(chain, {
    founders: [alexa.publicKey, billy.publicKey, carol.publicKey],
    threshold: 2,
  })
  .signed(signature({ sender: alexa }))
  .apply(onOwnershipSwap, (events) => { /* ... */ })
  .run()

The root Rune's run method would be this-typed as containing no placeheld items, unless they're typed as unioned with undefined. This would ensure that devs didn't accidentally .run() their Runes without having applied required types.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: No status
Development

No branches or pull requests

2 participants