Skip to content

Set up infrastructure to allow the creation of extension packages #42

@webJose

Description

@webJose

Issue #8 is a desirable feature. The problem with the current state of the library in regard to this feature request, is that it directly uses the History API to perform navigation, and Sveltekit doesn't like this (looks like Sveltekit stubs the History API) and emits a warning saying: "Don't mess with History API; use Sveltekit-approved means of navigation".

The current code for navigation is owned by the LocationLite class (which is inherited by LocationFull). This covers all Location implementations so far. A new Location class is needed to navigate differently. In the case of Sveltekit, to route with goto(), most likely.

Now we can see these challenges:

  1. Not all of the current library options for initialization can be made to work with Sveltekit. These will need to be restricted. For example, path routing needs to be forbidden so as to not interfere with standard Sveltekit routing.
  2. We need to optionally import @sveltejs/kit. Otherwise, we don't get the necessary means to navigate. It must be an optional package because @wjfe/n-savant is a SPA router thought for CSR Svelte applications.
  3. How do we support the extra functionality that goto() provides, like maintaining focus or scroll position?
  4. Do we update the Link component with more props that cover the extra functionality, even though those only work for Sveltekit and will probably confuse developers that do non-Sveltekit projects?

These are difficult challenges, but this is what this issue is for.

Proposal

Expose as public API enough core API to allow other NPM packages to build on top of @wjfe/n-savant. Then we can overcome all of the above challenges much more easily by simply creating the @wjfe/n-savant-sk NPM package.

This new package would provide its own init() function that only accepts the library options that make sense and also has total freedom to add Sveltekit-only options. It will also be able to require @sveltejs/kit normally as a peer dependency.

As for navigation, it can add a new navigate() overload that accepts Sveltekit's goto() features that the base package doesn't and can even provide its own Link component.

All challenges are much more easily addressed.

Identified API

API Object Type Reason
setLocation Function It sets or unsets the global location object. A must for extension packages.
setTraceOptions Function It sets the router tracing options for the RouterTrace component.
routingOptions Global object It holds the library's global routing options, pre-initialized with the documented default values.
LocationLite Class Classes can be inherited. This can prove useful for a future extension package.
LocationFull Class Classes can be inherited. This can prove useful for a future extension package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: MediumMedium priority. Upvote to request a higher priority. Downvote to attempt to lower priority.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions