This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
Scopes and how I used nested registries #46
pauleveritt
started this conversation in
General
Replies: 1 comment
-
I'll give a companion usage, besides just caching: Traditionally systems treat this as a template slot problem. Others are a little more advanced, such as With per-request state, a component can grab a stateful service and say "include this CSS file as a link" or "inline this JS in the head". That state accumulates, then at the end of the request, gets consolidated and generated by a template/component. Somewhat like middleware or a Pyramid tween. But with more framework support, more advanced and useful patterns of pluggability and generation could emerge. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think @Finistere is interested in re-thinking scopes. I know @flisboac also had an interest.
I'll describe what I did in Hopscotch, informed by wired, in support of what I wanted for my Sphinxy-componenty project. It's not a request for something similar, just as FYI.
I approach this as layers: the framework, the app, a site, a plugin, and site customizations. When the process starts up, it loads registrations for each layer...actually, with some static config that loads first.
When you want a result for something -- either imperatively or via injection -- the target is looked up, instantiated, and cached.
This might happen once for the app process lifetime. But it might happen in a per-request basis.
Let's do an example. Let's say there's a logo component in the top left. All pages have it and it doesn't change. You something asks for the
<Logo />
and it locates the right implementation, constructs it, and caches it. (In a perfect world, persistently.)But the page heading is different. It changes from resource to resource. When you ask for a
<Heading />
for a page:Heading
implementations...class DocumentHeading(Heading)
,class ImageHeading(Heading)
, etc./folder1/doc27
has a title for that documentEven
Logo
is weird. You might have some pages that don't have a logo, or override it for just that page.In Hopscotch, I have nested registries. So something like this:
The registrations are done once at site startup. (Though not necessarily. I could always do
resource_registry.scan()
. But it seems a too-dynamic idea.)The child registry gets some information added into it that specifies the lookups. This is similar-ish to
qualified_by
forinject.get[Hook].single(qualified_by=Event.SHUTDOWN)
in Antidote, but it continues into all future lookups while in that child registry.Notably, the cache is "as local as you can be". Some results are in the child registry. They are thrown out when it is deleted.
This idea is full of holes. But maybe it prompts some good ideas. Kind of like SQL transaction and sub-transaction. Or Python nested context managers. Or Docker "layers".
But it's for sure hard. Especially if you want to adopt "push"....something changes, you find its dependants and update them, and their dependants, etc.
Sorry, long note. Thanks for listening.
Beta Was this translation helpful? Give feedback.
All reactions