Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve internal route and parameter parsing (#330)
* Tokenize all route template parameter segments (e.g. `{post?}`) into descriptive objects: - immediately extract the name of every parameter present in the route template - check what the type of the passed parameters *is* (instead of what it *isn't*) so that we can wrap strings and integers in an array and completely ignore objects - pre-fill default parameters immediately - remove the numericParamIndices flag and conditionals that check for it - remove conditionals that depend on missing parameter key names, since there now shouldn't ever be any * Fix default parameter assignment and merging, formatting * Refactor core parameter matching logic: - use route model binding keys more frequently now that they're always available - use type checks to return early for non-object parameter values - don't modify the parameters object with `delete` during matching - normalize single object parameters properly * Replace UrlBuilder class with simplified getters on main Router class - remove unreachable error thrown if the provided `name` is undefined (called from UrlBuilder which was only instantiated at all if `name` was set) - return early from hydrateUrl if there are no template segments to replace - error as early as possible on non-existent routes - remove check for pre-existing hydrated URL (this never happened) - formatting * Formatting * Add support for parsing query parameters out of current URL, formatting, update tests * Re-implement current route checking with full support for partially matching params - Remove matchUrl method (undocumented, only used internally, and pretty much useless on its own) - Refactor some internal methods to accept a route so they can be used in any context - Match passed params partially against current route - Add option to match passed params exactly when necessary - Remove normalizeParams method and replace with internal _parseParameters() - Formatting and renaming things * Cleanup - extract new substituteBindings helper and replace switch statements - extract new dehydrate helper - add comments and jsdocs - improve error messages - rename and deprecate things, mostly maintaining backwards compatibility - add class properties - rename internal configuration object from 'ziggy' to 'config' * Enable microbundle property mangling to reduce size and restrict internal APIs See /~https://github.com/developit/microbundle#mangling-properties * Formatting, errors, organization, and comments * Remove `exact` flag from `current()` * Add tests for errors, strings, and bindings * :) * Update description and tightenco → tighten * Remove comment * Cleanup * Collapse everything into a simple new Route class * Clean up formatting and comments, rename _locationURL to _dehydrate * Check for Ziggy config on `globalThis` as a fallback * Remove tests for removed/deprecated methods * Parse the current URL once instead of for each route * Make config and queryParams private * Revert "Update description and tightenco → tighten" This reverts commit c22342c. * Update Changelog * Add and improve comments, rename/reorder methods * Add implicit test coverage for default parameters * Allow fallback route model 'binding' of 'id' to increase backwards compatibility * Formatting
- Loading branch information