@manyducks.co/dolla 0.75.1 → 0.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -2995,6 +2995,9 @@ function resolvePath(base, part) {
2995
2995
  function parseQueryParams(query) {
2996
2996
  if (!query)
2997
2997
  return {};
2998
+ if (query.startsWith("?")) {
2999
+ query = query.slice(1);
3000
+ }
2998
3001
  const entries = query.split("&").filter((x) => x.trim() !== "").map((entry) => {
2999
3002
  const [key, value] = entry.split("=").map((x) => x.trim());
3000
3003
  if (value.toLowerCase() === "true") {
@@ -3252,21 +3255,19 @@ function RouterStore(ctx) {
3252
3255
  const $$pattern = $$(null);
3253
3256
  const $$path = $$("");
3254
3257
  const $$params = $$({});
3255
- const $$query = $$({});
3256
- let isRouteChange = true;
3258
+ const $$query = $$(parseQueryParams(window.location.search));
3257
3259
  ctx.observe($$query, (current) => {
3258
- if (isRouteChange) {
3259
- isRouteChange = false;
3260
- return;
3261
- }
3262
3260
  const params = new URLSearchParams();
3263
3261
  for (const key in current) {
3264
3262
  params.set(key, String(current[key]));
3265
3263
  }
3266
- history.replace({
3267
- pathname: history.location.pathname,
3268
- search: "?" + params.toString()
3269
- });
3264
+ const search = "?" + params.toString();
3265
+ if (search != history.location.search) {
3266
+ history.replace({
3267
+ pathname: history.location.pathname,
3268
+ search
3269
+ });
3270
+ }
3270
3271
  });
3271
3272
  ctx.onConnected(() => {
3272
3273
  history.listen(onRouteChange);
@@ -3286,8 +3287,7 @@ function RouterStore(ctx) {
3286
3287
  const onRouteChange = async ({ location }) => {
3287
3288
  if (location.search !== lastQuery) {
3288
3289
  lastQuery = location.search;
3289
- isRouteChange = true;
3290
- $$query.set(parseQueryParams(location.search.startsWith("?") ? location.search.slice(1) : location.search));
3290
+ $$query.set(parseQueryParams(location.search));
3291
3291
  }
3292
3292
  const matched = matchRoutes(routes, location.pathname);
3293
3293
  if (!matched) {
@@ -3399,6 +3399,9 @@ function RouterStore(ctx) {
3399
3399
  joined = path.toString();
3400
3400
  }
3401
3401
  joined = resolvePath(history.location.pathname, joined);
3402
+ if (options.preserveQuery) {
3403
+ joined += history.location.search;
3404
+ }
3402
3405
  if (options.replace) {
3403
3406
  history.replace(joined);
3404
3407
  } else {