@manyducks.co/dolla 0.74.0 → 0.75.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 +39 -15
- package/lib/index.js.map +2 -2
- package/lib/stores/router.d.ts +5 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1576,7 +1576,6 @@ function initView(config) {
|
|
|
1576
1576
|
}
|
|
1577
1577
|
},
|
|
1578
1578
|
async setChildren(children) {
|
|
1579
|
-
console.log("setChildren", { name: ctx.name, children });
|
|
1580
1579
|
$$children.set(children);
|
|
1581
1580
|
}
|
|
1582
1581
|
};
|
|
@@ -3221,20 +3220,19 @@ function RouterStore(ctx) {
|
|
|
3221
3220
|
if (route.meta.redirect) {
|
|
3222
3221
|
let redirectPath;
|
|
3223
3222
|
if (isFunction(route.meta.redirect)) {
|
|
3224
|
-
throw new Error(`Redirect functions are not yet supported.`);
|
|
3225
3223
|
} else if (isString(route.meta.redirect)) {
|
|
3226
3224
|
redirectPath = route.meta.redirect;
|
|
3225
|
+
const match = matchRoutes(routes, redirectPath, {
|
|
3226
|
+
willMatch(r) {
|
|
3227
|
+
return r !== route;
|
|
3228
|
+
}
|
|
3229
|
+
});
|
|
3230
|
+
if (!match) {
|
|
3231
|
+
throw new Error(`Found a redirect to an undefined URL. From '${route.pattern}' to '${route.meta.redirect}'`);
|
|
3232
|
+
}
|
|
3227
3233
|
} else {
|
|
3228
3234
|
throw new TypeError(`Expected a string or redirect function. Got: ${route.meta.redirect}`);
|
|
3229
3235
|
}
|
|
3230
|
-
const match = matchRoutes(routes, redirectPath, {
|
|
3231
|
-
willMatch(r) {
|
|
3232
|
-
return r !== route;
|
|
3233
|
-
}
|
|
3234
|
-
});
|
|
3235
|
-
if (!match) {
|
|
3236
|
-
throw new Error(`Found a redirect to an undefined URL. From '${route.pattern}' to '${route.meta.redirect}'`);
|
|
3237
|
-
}
|
|
3238
3236
|
}
|
|
3239
3237
|
}
|
|
3240
3238
|
ctx.onConnected(() => {
|
|
@@ -3330,14 +3328,25 @@ function RouterStore(ctx) {
|
|
|
3330
3328
|
ctx.info(`Matched route: '${matched.pattern}' ('${matched.path}')`);
|
|
3331
3329
|
if (matched.meta.redirect != null) {
|
|
3332
3330
|
if (typeof matched.meta.redirect === "string") {
|
|
3333
|
-
|
|
3334
|
-
for (const key in matched.params) {
|
|
3335
|
-
path = path.replace(":" + key, matched.params[key].toString());
|
|
3336
|
-
}
|
|
3331
|
+
const path = replaceParams(matched.meta.redirect, matched.params);
|
|
3337
3332
|
ctx.info(`Redirecting to: '${path}'`);
|
|
3338
3333
|
history.replace(path);
|
|
3339
3334
|
} else if (typeof matched.meta.redirect === "function") {
|
|
3340
|
-
|
|
3335
|
+
const redirectContext = {
|
|
3336
|
+
path: matched.path,
|
|
3337
|
+
pattern: matched.pattern,
|
|
3338
|
+
params: matched.params,
|
|
3339
|
+
query: matched.query
|
|
3340
|
+
};
|
|
3341
|
+
let path = await matched.meta.redirect(redirectContext);
|
|
3342
|
+
if (typeof path !== "string") {
|
|
3343
|
+
throw new Error(`Redirect function must return a path to redirect to.`);
|
|
3344
|
+
}
|
|
3345
|
+
if (!path.startsWith("/")) {
|
|
3346
|
+
path = resolvePath(matched.path, path);
|
|
3347
|
+
}
|
|
3348
|
+
ctx.info(`Redirecting to: '${path}'`);
|
|
3349
|
+
history.replace(path);
|
|
3341
3350
|
} else {
|
|
3342
3351
|
throw new TypeError(`Redirect must either be a path string or a function.`);
|
|
3343
3352
|
}
|
|
@@ -3424,6 +3433,14 @@ function RouterStore(ctx) {
|
|
|
3424
3433
|
* @param args - One or more path segments optionally followed by an options object.
|
|
3425
3434
|
*/
|
|
3426
3435
|
navigate
|
|
3436
|
+
/**
|
|
3437
|
+
* Updates a query param in place.
|
|
3438
|
+
*/
|
|
3439
|
+
// updateQuery(key: string, value: string) {},
|
|
3440
|
+
/**
|
|
3441
|
+
* Updates a route param in place.
|
|
3442
|
+
*/
|
|
3443
|
+
// updateParam(key: string, value: string) {},
|
|
3427
3444
|
};
|
|
3428
3445
|
}
|
|
3429
3446
|
var safeExternalLink = /(noopener|noreferrer) (noopener|noreferrer)/;
|
|
@@ -3457,6 +3474,13 @@ function catchLinks(root, callback, _window = window) {
|
|
|
3457
3474
|
root.removeEventListener("click", handler);
|
|
3458
3475
|
};
|
|
3459
3476
|
}
|
|
3477
|
+
function replaceParams(path, params) {
|
|
3478
|
+
for (const key in params) {
|
|
3479
|
+
const value = params[key].toString();
|
|
3480
|
+
path = path.replace(`{${key}}`, value).replace(`{#${key}}`, value);
|
|
3481
|
+
}
|
|
3482
|
+
return path;
|
|
3483
|
+
}
|
|
3460
3484
|
|
|
3461
3485
|
// src/stores/language.ts
|
|
3462
3486
|
function LanguageStore(ctx) {
|