Consume/Provide Decorators
j
Just wanted to drop this here, unfortunately don't have time for more Zoom, but I got my consume decorator to work. You can now save a few lines of code per context by applying it as a decorator directly on an accessor/setter property:
Copy code
ts
    @consume({
        context: UMB_APP_LOG_VIEWER_CONTEXT,
    })
    private set _logViewerContext(value: typeof UMB_APP_LOG_VIEWER_CONTEXT.TYPE | undefined) {
        this.#logViewerContext = value;
        this.#observeErrorCount();
        this.#observeCanShowLogs();
        value?.getLogLevels(0, 100);
    }
    private get _logViewerContext() {
        return this.#logViewerContext;
    }
You can also apply Lit's
@state()
decorator and make it reactive, if it holds state to render in the template or something to that effect. It follows the same syntax as
@lit/context
so should be interchangable. Next up is a
@provide
decorator, and that should be it for the Context API. In the future, who knows, maybe a
@shortcut()
decorator for method invocation?
w
This make it into the CMS in the end?
j
I think so Warren. It augments the existing mechanisms without altering anything. It just uses a context/provide controller behind the scenes. I have also now built the
@provide
decorator and added unit tests. It looks pretty stable. Could be nice if someone wanted to test it out locally in their package (you can just copy the code in) before it lands in the CMS. But the code is branched off of v17, so could maybe target 17.1 if all goes well...
5 Views