ModuleStackCodec<R extends KaiselRoute> class
abstract
Codec for a module's URL structure, relative to whatever prefix the host mounts the module at.
Module authors implement this to make their module URL-addressable. The host composes it via ConfigCodecWithModules without needing to know the module's internal route types. The module ships as a self-contained unit.
class CheckoutModuleCodec extends ModuleStackCodec<CheckoutRoute> {
const CheckoutModuleCodec();
@override
List<String> encode(List<CheckoutRoute> stack) => switch (stack.last) {
CheckoutCart() => const [],
CheckoutShipping() => const ['shipping'],
CheckoutConfirm() => const ['confirm'],
};
@override
List<CheckoutRoute>? decode(List<String> segments) => switch (segments) {
[] => const [CheckoutCart()],
['shipping'] => const [CheckoutCart(), CheckoutShipping()],
['confirm'] => const [
CheckoutCart(), CheckoutShipping(), CheckoutConfirm(),
],
_ => null,
};
}
Conventions:
encodeof the module's root state returnsconst []. The mount prefix alone (e.g./checkout) is enough.decodeofconst []should return the module's root stack (typicallyinitialStack), so visiting just the prefix lands the module at its starting position.- Return
nullfromdecodefor unknown segment patterns. The parser falls back to its configured fallback stack.
- Implemented types
Constructors
- ModuleStackCodec()
-
Const constructor so subclasses can be
const.const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
decode(
List< String> segments) → List<R> ? -
Decode URL segments (relative to the mount prefix) into a
module stack. Return
nullif the segments don't match any known route in this module. -
decodeAny(
List< String> segments) → List<KaiselRoute> ? -
Decode URL segments to a stack of routes, or
nullif the segments don't match any known route in this module. Implementations upcast their specific route subtype to KaiselRoute for the composer.override -
encode(
List< R> stack) → List<String> -
Encode the module's stack to URL segments. The result is
appended to the host's mount prefix to produce the full URL.
Return
const []for the module's root state. -
encodeAny(
List< KaiselRoute> stack) → List<String> -
Encode any stack of routes to URL segments. Implementations
downcast to their module's specific route type internally.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited