{@thread.name}

_ahey
2023-06-05

_ahey:

Is it possible to dynamically (at compile time) add a notifier to a resource, from within the transformer of an extension on another resource?

zachdaniel:

It’s not possible to alter one resource from another, generally speaking

_ahey:

Thanks, i think i can include another extension on the other resources that introspects the primary resource to decide whether to add the notifiers

zachdaniel:

You might run into trouble with that one also honestly

_ahey:

Order of compilation issues?

zachdaniel:

Yep.

zachdaniel:

What I’d suggest: write a registry extension that validates that the extension is on any required resources

zachdaniel:

Since the registry compiles after all resources in the registry.

_ahey:

Cool, I will look into this. I’m cooking up a way to very easily cache complex complex calculations to database attributes.

zachdaniel:

Actually I may have made a change recently that makes that problematic 🥲 this was changed to a verifier but it should be a transformer https://github.com/ash-project/ash/blob/main/lib/ash/registry/extensions/resource_validations/verifiers/ensure_resources_compiled.ex

zachdaniel:

The other way to do it is to list which resources must have the extension in compile time config.

zachdaniel:

One resource validates that the compile time config includes it, and the registry extension ensures that each resource in the compile time config that is in the registry (after ensuring they are compiled using https://hexdocs.pm/elixir/1.12/Code.html#ensure_compiled!/1 ) also uses that extension.

_ahey:

Thanks for the info! Will have a crack at it tomorrow

_ahey:

I’ve decided to be pragmatic with this – I will add my extension to each resource that is involved, and add the config via dsl that each resource needs, rather than trying to add all config to one resource and have others read it. This approach means there will be no compilation order issues.

zachdaniel:

👍

zachdaniel:

sounds like a prudent idea

zachdaniel:

I’ve been around exactly that same block