Repository navigation
Generate per-call dispatchers for Dispatchable interfaces - #1
Merged
Merged
Conversation
…ace-name collisions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Dispatchable<TContext = void>marker (extendsImplScan, which stays memberless and unchanged for existing users).Dispatchableinterface the CLI generates a<Interface>Dispatcherclass that implements the interface and forwards each member to the applicable implementation (isApplicableTo/ highestgetPriority()), resolved on every call. The context comes from a generated<INTERFACE>_CONTEXTtoken typed() => TContext; the plain target takes implementations and context function in the constructor.app.config.ts:DispatchContextProvider<TContext>next to the interface is found by the scan, andprovideImplscan()builds the context token from it;extends Dispatchablewithout a type argument is context-free:isApplicableTo()takes no parameter, no token is generated, each implementation decides from what it injects;src/dispatcher.tsmodule: signature copying,import typeresolution through the type checker, unsupported shapes (overloads, optional members, destructured params, accessors,thistypes, index/call signatures, generic interfaces or bases, non-exported types, import-name collisions,import()types) get a warning while list and token are still generated.PaymentHandlerdispatched byPaymentContextthrough a scannedPaymentContextProvider, context-freeReceiptFormatter(RECEIPT_FORMAT=md),Notifierstays a plain list. README, smoke test and CI updated;npm testadded.Test plan
npm test: 40 generator, CLI and runtime dispatcher testsnpm run typecheck,npm run buildnpm start/npm run start:angularthrough realinject(); the Angular demo provides only its own settings tokennpm run generatetwice is byte-identicalnpm run test:packageagainst the packed tarballng build(AOT, Angular CLI 22.2, TypeScript 6.0) in a scratch app: build clean, app renders, dispatcher and context provider resolve through real DI, per-call switching verified in the browser