Skip to content

Commit

Permalink
Allow args.conditions to be a single item, converted to array
Browse files Browse the repository at this point in the history
  • Loading branch information
ItalyPaleAle committed Sep 20, 2020
1 parent 40d82d7 commit 92f908a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* @property {function(): Promise<SvelteComponent>} [asyncRoute] - Function that returns a Promise that fulfills with a Svelte component (e.g. `{asyncRoute: () => import('Foo.svelte')}`)
* @property {SvelteComponent} [loadingRoute] - Svelte component to be displayed while the async route is loading; when unset or false-y, no route is shown while loading
* @property {Object} [loadingParams] - Optional dictionary passed to the `loadingRoute` component as params (for an exported prop called `params`)
* @property {Object} [userData] - Optional object that will be passed to each `conditionsFailed` event (can be omitted)
* @property {RoutePrecondition[]} [conditions] - Route pre-conditions to add, which will be executed in order
* @property {Object} [userData] - Optional object that will be passed to events such as `routeLoading`, `routeLoaded`, `conditionsFailed`
* @property {RoutePrecondition[]|RoutePrecondition} [conditions] - Route pre-conditions to add, which will be executed in order
*/

/**
Expand Down Expand Up @@ -47,7 +47,11 @@ export function wrap(args) {
if (typeof args.asyncRoute != 'function') {
throw Error('Parameter asyncRoute must be a function')
}
if (args.conditions && args.conditions.length) {
if (args.conditions) {
// Ensure it's an array
if (!Array.isArray(args.conditions)) {
args.conditions = [args.conditions]
}
for (let i = 0; i < args.conditions.length; i++) {
if (!args.conditions[i] || typeof args.conditions[i] != 'function') {
throw Error('Invalid parameter conditions[' + i + ']')
Expand Down

0 comments on commit 92f908a

Please sign in to comment.