Comparing version 0.10.10 to 0.10.12-0
@@ -8,7 +8,7 @@ import { Resolvable } from './Resolver'; | ||
title?: string; | ||
getTitle?: Resolvable<string>; | ||
getTitle?: Resolvable<string, Context, Meta>; | ||
meta?: Meta; | ||
getMeta?: Resolvable<Meta>; | ||
getMeta?: Resolvable<Meta, Context>; | ||
content?: Content; | ||
getContent?: Resolvable<Content>; | ||
getContent?: Resolvable<Content, Context, Meta>; | ||
} | ||
@@ -23,8 +23,8 @@ export declare class PageMatcher<Context extends object, Meta extends object, Content> extends NodeMatcher<Context> { | ||
title?: string; | ||
getTitle?: Resolvable<string>; | ||
getTitle?: Resolvable<string, Context, Meta>; | ||
meta?: Meta; | ||
getMeta?: Resolvable<Meta>; | ||
getMeta?: Resolvable<Meta, Context>; | ||
content?: Content; | ||
getContent?: Resolvable<Content, Context>; | ||
getContent?: Resolvable<Content, Context, Meta>; | ||
}): Page<Context, Meta, Content>; | ||
export declare function isValidPage(x: any): x is Page; |
@@ -37,5 +37,18 @@ "use strict"; | ||
var error; | ||
// Meta must come first, as the promise to its result can be used by | ||
// the subsequent resolvables. | ||
var meta; | ||
if (this.constructor.getMeta) { | ||
var metaResolution = this.resolver.resolve(this.env, this.constructor.getMeta); | ||
resolutionIds.push(metaResolution.id); | ||
meta = metaResolution.value; | ||
status = Resolver_1.reduceStatuses(status, metaResolution.status); | ||
error = error || metaResolution.error; | ||
} | ||
else { | ||
meta = this.constructor.meta; | ||
} | ||
var content; | ||
if (this.withContent && this.constructor.getContent) { | ||
var contentResolution = this.resolver.resolve(this.env, this.constructor.getContent); | ||
var contentResolution = this.resolver.resolve(this.env, this.constructor.getContent, this.constructor.getMeta); | ||
resolutionIds.push(contentResolution.id); | ||
@@ -51,3 +64,3 @@ content = contentResolution.value; | ||
if (this.constructor.getTitle) { | ||
var titleResolution = this.resolver.resolve(this.env, this.constructor.getTitle); | ||
var titleResolution = this.resolver.resolve(this.env, this.constructor.getTitle, this.constructor.getMeta); | ||
resolutionIds.push(titleResolution.id); | ||
@@ -61,13 +74,2 @@ title = titleResolution.value; | ||
} | ||
var meta; | ||
if (this.constructor.getMeta) { | ||
var metaResolution = this.resolver.resolve(this.env, this.constructor.getMeta); | ||
resolutionIds.push(metaResolution.id); | ||
meta = metaResolution.value; | ||
status = Resolver_1.reduceStatuses(status, metaResolution.status); | ||
error = error || metaResolution.error; | ||
} | ||
else { | ||
meta = this.constructor.meta; | ||
} | ||
return { | ||
@@ -74,0 +76,0 @@ resolutionIds: resolutionIds, |
import { Env } from './Env'; | ||
export declare type Resolvable<T, Context extends object = any> = (env: Env<Context>) => (T | PromiseLike<{ | ||
export declare type Resolvable<T, Context extends object = any, Data = any> = (env: Env<Context>, dataPromise: PromiseLike<Data>) => (T | PromiseLike<{ | ||
default: T; | ||
@@ -8,2 +8,3 @@ } | T>); | ||
status: Status; | ||
promise: PromiseLike<T>; | ||
error?: any; | ||
@@ -22,8 +23,7 @@ value?: T; | ||
private listenerIds; | ||
private isDisposed; | ||
constructor(); | ||
listen(listener: () => void, resolutionIds: number[]): void; | ||
unlisten(listener: () => void): void; | ||
resolve<T>(env: Env<any>, resolvable: Resolvable<T>): Resolution<T>; | ||
listenForChanges<T>(maybeValue: PromiseLike<T>, matcherResults: Map<Function, Resolution<T>>, resolvable: Resolvable<T>, id: number, fullPathname: string): void; | ||
resolve<T, Data>(env: Env<any>, resolvable: Resolvable<T>, dataResolvable?: Resolvable<Data>): Resolution<T>; | ||
listenForChanges<T>(promise: PromiseLike<T>, matcherResults: Map<Function, Resolution<T>>, resolvable: Resolvable<T>, id: number, fullPathname: string): void; | ||
} |
@@ -26,3 +26,2 @@ "use strict"; | ||
this.results = new WeakMap(); | ||
this.isDisposed = false; | ||
} | ||
@@ -35,3 +34,3 @@ Resolver.prototype.listen = function (listener, resolutionIds) { | ||
}; | ||
Resolver.prototype.resolve = function (env, resolvable) { | ||
Resolver.prototype.resolve = function (env, resolvable, dataResolvable) { | ||
var matcherResults = this.results.get(env); | ||
@@ -46,4 +45,5 @@ if (!matcherResults) { | ||
} | ||
var dataResolution = !dataResolvable ? { promise: Promise.resolve() } : (matcherResults.get(dataResolvable) || { promise: Promise.resolve() }); | ||
var id = this.nextId++; | ||
var maybeValue = resolvable(env); | ||
var maybeValue = resolvable(env, dataResolution.promise); | ||
if (!isPromiseLike(maybeValue)) { | ||
@@ -54,2 +54,3 @@ var result_1 = { | ||
value: maybeValue, | ||
promise: Promise.resolve(maybeValue), | ||
}; | ||
@@ -59,13 +60,15 @@ matcherResults.set(resolvable, result_1); | ||
} | ||
var promise = maybeValue.then(extractDefault); | ||
var result = { | ||
id: id, | ||
status: Status.Busy, | ||
promise: promise, | ||
}; | ||
matcherResults.set(resolvable, result); | ||
this.listenForChanges(maybeValue, matcherResults, resolvable, id, URLTools_1.joinPaths(env.pathname, env.unmatchedPathnamePart)); | ||
this.listenForChanges(promise, matcherResults, resolvable, id, URLTools_1.joinPaths(env.pathname, env.unmatchedPathnamePart)); | ||
return result; | ||
}; | ||
Resolver.prototype.listenForChanges = function (maybeValue, matcherResults, resolvable, id, fullPathname) { | ||
Resolver.prototype.listenForChanges = function (promise, matcherResults, resolvable, id, fullPathname) { | ||
var _this = this; | ||
maybeValue | ||
promise | ||
.then(function (value) { | ||
@@ -77,3 +80,4 @@ var currentResult = matcherResults.get(resolvable); | ||
status: Status.Ready, | ||
value: extractDefault(value), | ||
value: value, | ||
promise: promise, | ||
}); | ||
@@ -92,2 +96,3 @@ return true; | ||
error: error || new Error(), | ||
promise: promise, | ||
}); | ||
@@ -94,0 +99,0 @@ return true; |
@@ -12,7 +12,7 @@ import { Resolvable } from './Resolver'; | ||
title?: string; | ||
getTitle?: Resolvable<string, Context>; | ||
getTitle?: Resolvable<string, Context, Meta>; | ||
meta?: Meta; | ||
getMeta?: Resolvable<Meta, Context>; | ||
content?: Content; | ||
getContent?: Resolvable<Content, Context>; | ||
getContent?: Resolvable<Content, Context, Meta>; | ||
paths: SwitchPaths<Context>; | ||
@@ -41,8 +41,8 @@ orderedMappings: Mapping[]; | ||
meta?: Meta; | ||
getMeta?: Resolvable<Meta>; | ||
getMeta?: Resolvable<Meta, Context>; | ||
title?: string; | ||
getTitle?: Resolvable<string>; | ||
getTitle?: Resolvable<string, Context, Meta>; | ||
content?: Content; | ||
getContent?: Resolvable<Content, Context>; | ||
getContent?: Resolvable<Content, Context, Meta>; | ||
}): Switch<Context, Meta, Content>; | ||
export declare function isValidSwitch(x: any): x is Switch; |
@@ -59,9 +59,21 @@ "use strict"; | ||
SwitchMatcher.prototype.execute = function () { | ||
var hasContent = this.withContent && this.constructor.getContent; | ||
var resolutionIds = []; | ||
var status = Resolver_1.Status.Ready; | ||
var error; | ||
// Meta must come first, as the promise to its result can be used by | ||
// the subsequent resolvables. | ||
var meta; | ||
if (this.constructor.getMeta) { | ||
var metaResolution = this.resolver.resolve(this.env, this.constructor.getMeta); | ||
resolutionIds.push(metaResolution.id); | ||
meta = metaResolution.value; | ||
status = Resolver_1.reduceStatuses(status, metaResolution.status); | ||
error = error || metaResolution.error; | ||
} | ||
else { | ||
meta = this.constructor.meta; | ||
} | ||
var content; | ||
if (this.withContent && this.constructor.getContent) { | ||
var contentResolution = this.resolver.resolve(this.env, this.constructor.getContent); | ||
var contentResolution = this.resolver.resolve(this.env, this.constructor.getContent, this.constructor.getMeta); | ||
resolutionIds.push(contentResolution.id); | ||
@@ -77,3 +89,3 @@ content = contentResolution.value; | ||
if (this.constructor.getTitle) { | ||
var titleResolution = this.resolver.resolve(this.env, this.constructor.getTitle); | ||
var titleResolution = this.resolver.resolve(this.env, this.constructor.getTitle, this.constructor.getMeta); | ||
resolutionIds.push(titleResolution.id); | ||
@@ -87,13 +99,2 @@ title = titleResolution.value; | ||
} | ||
var meta; | ||
if (this.constructor.getMeta) { | ||
var metaResolution = this.resolver.resolve(this.env, this.constructor.getMeta); | ||
resolutionIds.push(metaResolution.id); | ||
meta = metaResolution.value; | ||
status = Resolver_1.reduceStatuses(status, metaResolution.status); | ||
error = error || metaResolution.error; | ||
} | ||
else { | ||
meta = this.constructor.meta; | ||
} | ||
var childMatcher; | ||
@@ -100,0 +101,0 @@ var childNodeResolution; |
@@ -8,7 +8,7 @@ import { Resolvable } from './Resolver'; | ||
title?: string; | ||
getTitle?: Resolvable<string>; | ||
getTitle?: Resolvable<string, Context, Meta>; | ||
meta?: Meta; | ||
getMeta?: Resolvable<Meta>; | ||
getMeta?: Resolvable<Meta, Context>; | ||
content?: Content; | ||
getContent?: Resolvable<Content>; | ||
getContent?: Resolvable<Content, Context, Meta>; | ||
} | ||
@@ -23,8 +23,8 @@ export declare class PageMatcher<Context extends object, Meta extends object, Content> extends NodeMatcher<Context> { | ||
title?: string; | ||
getTitle?: Resolvable<string>; | ||
getTitle?: Resolvable<string, Context, Meta>; | ||
meta?: Meta; | ||
getMeta?: Resolvable<Meta>; | ||
getMeta?: Resolvable<Meta, Context>; | ||
content?: Content; | ||
getContent?: Resolvable<Content, Context>; | ||
getContent?: Resolvable<Content, Context, Meta>; | ||
}): Page<Context, Meta, Content>; | ||
export declare function isValidPage(x: any): x is Page; |
@@ -35,5 +35,18 @@ var __extends = (this && this.__extends) || (function () { | ||
var error; | ||
// Meta must come first, as the promise to its result can be used by | ||
// the subsequent resolvables. | ||
var meta; | ||
if (this.constructor.getMeta) { | ||
var metaResolution = this.resolver.resolve(this.env, this.constructor.getMeta); | ||
resolutionIds.push(metaResolution.id); | ||
meta = metaResolution.value; | ||
status = reduceStatuses(status, metaResolution.status); | ||
error = error || metaResolution.error; | ||
} | ||
else { | ||
meta = this.constructor.meta; | ||
} | ||
var content; | ||
if (this.withContent && this.constructor.getContent) { | ||
var contentResolution = this.resolver.resolve(this.env, this.constructor.getContent); | ||
var contentResolution = this.resolver.resolve(this.env, this.constructor.getContent, this.constructor.getMeta); | ||
resolutionIds.push(contentResolution.id); | ||
@@ -49,3 +62,3 @@ content = contentResolution.value; | ||
if (this.constructor.getTitle) { | ||
var titleResolution = this.resolver.resolve(this.env, this.constructor.getTitle); | ||
var titleResolution = this.resolver.resolve(this.env, this.constructor.getTitle, this.constructor.getMeta); | ||
resolutionIds.push(titleResolution.id); | ||
@@ -59,13 +72,2 @@ title = titleResolution.value; | ||
} | ||
var meta; | ||
if (this.constructor.getMeta) { | ||
var metaResolution = this.resolver.resolve(this.env, this.constructor.getMeta); | ||
resolutionIds.push(metaResolution.id); | ||
meta = metaResolution.value; | ||
status = reduceStatuses(status, metaResolution.status); | ||
error = error || metaResolution.error; | ||
} | ||
else { | ||
meta = this.constructor.meta; | ||
} | ||
return { | ||
@@ -72,0 +74,0 @@ resolutionIds: resolutionIds, |
import { Env } from './Env'; | ||
export declare type Resolvable<T, Context extends object = any> = (env: Env<Context>) => (T | PromiseLike<{ | ||
export declare type Resolvable<T, Context extends object = any, Data = any> = (env: Env<Context>, dataPromise: PromiseLike<Data>) => (T | PromiseLike<{ | ||
default: T; | ||
@@ -8,2 +8,3 @@ } | T>); | ||
status: Status; | ||
promise: PromiseLike<T>; | ||
error?: any; | ||
@@ -22,8 +23,7 @@ value?: T; | ||
private listenerIds; | ||
private isDisposed; | ||
constructor(); | ||
listen(listener: () => void, resolutionIds: number[]): void; | ||
unlisten(listener: () => void): void; | ||
resolve<T>(env: Env<any>, resolvable: Resolvable<T>): Resolution<T>; | ||
listenForChanges<T>(maybeValue: PromiseLike<T>, matcherResults: Map<Function, Resolution<T>>, resolvable: Resolvable<T>, id: number, fullPathname: string): void; | ||
resolve<T, Data>(env: Env<any>, resolvable: Resolvable<T>, dataResolvable?: Resolvable<Data>): Resolution<T>; | ||
listenForChanges<T>(promise: PromiseLike<T>, matcherResults: Map<Function, Resolution<T>>, resolvable: Resolvable<T>, id: number, fullPathname: string): void; | ||
} |
@@ -23,3 +23,2 @@ import { joinPaths } from './URLTools'; | ||
this.results = new WeakMap(); | ||
this.isDisposed = false; | ||
} | ||
@@ -32,3 +31,3 @@ Resolver.prototype.listen = function (listener, resolutionIds) { | ||
}; | ||
Resolver.prototype.resolve = function (env, resolvable) { | ||
Resolver.prototype.resolve = function (env, resolvable, dataResolvable) { | ||
var matcherResults = this.results.get(env); | ||
@@ -43,4 +42,5 @@ if (!matcherResults) { | ||
} | ||
var dataResolution = !dataResolvable ? { promise: Promise.resolve() } : (matcherResults.get(dataResolvable) || { promise: Promise.resolve() }); | ||
var id = this.nextId++; | ||
var maybeValue = resolvable(env); | ||
var maybeValue = resolvable(env, dataResolution.promise); | ||
if (!isPromiseLike(maybeValue)) { | ||
@@ -51,2 +51,3 @@ var result_1 = { | ||
value: maybeValue, | ||
promise: Promise.resolve(maybeValue), | ||
}; | ||
@@ -56,13 +57,15 @@ matcherResults.set(resolvable, result_1); | ||
} | ||
var promise = maybeValue.then(extractDefault); | ||
var result = { | ||
id: id, | ||
status: Status.Busy, | ||
promise: promise, | ||
}; | ||
matcherResults.set(resolvable, result); | ||
this.listenForChanges(maybeValue, matcherResults, resolvable, id, joinPaths(env.pathname, env.unmatchedPathnamePart)); | ||
this.listenForChanges(promise, matcherResults, resolvable, id, joinPaths(env.pathname, env.unmatchedPathnamePart)); | ||
return result; | ||
}; | ||
Resolver.prototype.listenForChanges = function (maybeValue, matcherResults, resolvable, id, fullPathname) { | ||
Resolver.prototype.listenForChanges = function (promise, matcherResults, resolvable, id, fullPathname) { | ||
var _this = this; | ||
maybeValue | ||
promise | ||
.then(function (value) { | ||
@@ -74,3 +77,4 @@ var currentResult = matcherResults.get(resolvable); | ||
status: Status.Ready, | ||
value: extractDefault(value), | ||
value: value, | ||
promise: promise, | ||
}); | ||
@@ -89,2 +93,3 @@ return true; | ||
error: error || new Error(), | ||
promise: promise, | ||
}); | ||
@@ -91,0 +96,0 @@ return true; |
@@ -12,7 +12,7 @@ import { Resolvable } from './Resolver'; | ||
title?: string; | ||
getTitle?: Resolvable<string, Context>; | ||
getTitle?: Resolvable<string, Context, Meta>; | ||
meta?: Meta; | ||
getMeta?: Resolvable<Meta, Context>; | ||
content?: Content; | ||
getContent?: Resolvable<Content, Context>; | ||
getContent?: Resolvable<Content, Context, Meta>; | ||
paths: SwitchPaths<Context>; | ||
@@ -41,8 +41,8 @@ orderedMappings: Mapping[]; | ||
meta?: Meta; | ||
getMeta?: Resolvable<Meta>; | ||
getMeta?: Resolvable<Meta, Context>; | ||
title?: string; | ||
getTitle?: Resolvable<string>; | ||
getTitle?: Resolvable<string, Context, Meta>; | ||
content?: Content; | ||
getContent?: Resolvable<Content, Context>; | ||
getContent?: Resolvable<Content, Context, Meta>; | ||
}): Switch<Context, Meta, Content>; | ||
export declare function isValidSwitch(x: any): x is Switch; |
@@ -57,9 +57,21 @@ var __extends = (this && this.__extends) || (function () { | ||
SwitchMatcher.prototype.execute = function () { | ||
var hasContent = this.withContent && this.constructor.getContent; | ||
var resolutionIds = []; | ||
var status = Status.Ready; | ||
var error; | ||
// Meta must come first, as the promise to its result can be used by | ||
// the subsequent resolvables. | ||
var meta; | ||
if (this.constructor.getMeta) { | ||
var metaResolution = this.resolver.resolve(this.env, this.constructor.getMeta); | ||
resolutionIds.push(metaResolution.id); | ||
meta = metaResolution.value; | ||
status = reduceStatuses(status, metaResolution.status); | ||
error = error || metaResolution.error; | ||
} | ||
else { | ||
meta = this.constructor.meta; | ||
} | ||
var content; | ||
if (this.withContent && this.constructor.getContent) { | ||
var contentResolution = this.resolver.resolve(this.env, this.constructor.getContent); | ||
var contentResolution = this.resolver.resolve(this.env, this.constructor.getContent, this.constructor.getMeta); | ||
resolutionIds.push(contentResolution.id); | ||
@@ -75,3 +87,3 @@ content = contentResolution.value; | ||
if (this.constructor.getTitle) { | ||
var titleResolution = this.resolver.resolve(this.env, this.constructor.getTitle); | ||
var titleResolution = this.resolver.resolve(this.env, this.constructor.getTitle, this.constructor.getMeta); | ||
resolutionIds.push(titleResolution.id); | ||
@@ -85,13 +97,2 @@ title = titleResolution.value; | ||
} | ||
var meta; | ||
if (this.constructor.getMeta) { | ||
var metaResolution = this.resolver.resolve(this.env, this.constructor.getMeta); | ||
resolutionIds.push(metaResolution.id); | ||
meta = metaResolution.value; | ||
status = reduceStatuses(status, metaResolution.status); | ||
error = error || metaResolution.error; | ||
} | ||
else { | ||
meta = this.constructor.meta; | ||
} | ||
var childMatcher; | ||
@@ -98,0 +99,0 @@ var childNodeResolution; |
{ | ||
"name": "navi", | ||
"version": "0.10.10", | ||
"version": "0.10.12-0", | ||
"description": "A router-loader for React.", | ||
@@ -5,0 +5,0 @@ "author": "James K Nelson <james@jamesknelson.com>", |
@@ -16,7 +16,7 @@ import { Resolution, Resolvable, Status, reduceStatuses } from './Resolver' | ||
title?: string | ||
getTitle?: Resolvable<string> | ||
getTitle?: Resolvable<string, Context, Meta> | ||
meta?: Meta | ||
getMeta?: Resolvable<Meta> | ||
getMeta?: Resolvable<Meta, Context> | ||
content?: Content | ||
getContent?: Resolvable<Content> | ||
getContent?: Resolvable<Content, Context, Meta> | ||
} | ||
@@ -35,6 +35,27 @@ | ||
let error: any | ||
// Meta must come first, as the promise to its result can be used by | ||
// the subsequent resolvables. | ||
let meta: Meta | undefined | ||
if (this.constructor.getMeta) { | ||
let metaResolution = this.resolver.resolve( | ||
this.env, | ||
this.constructor.getMeta | ||
) | ||
resolutionIds.push(metaResolution.id) | ||
meta = metaResolution.value | ||
status = reduceStatuses(status, metaResolution.status) | ||
error = error || metaResolution.error | ||
} | ||
else { | ||
meta = this.constructor.meta | ||
} | ||
let content: Content | undefined | ||
if (this.withContent && this.constructor.getContent) { | ||
let contentResolution = this.resolver.resolve(this.env, this.constructor.getContent) | ||
let contentResolution = this.resolver.resolve( | ||
this.env, | ||
this.constructor.getContent, | ||
this.constructor.getMeta | ||
) | ||
resolutionIds.push(contentResolution.id) | ||
@@ -51,3 +72,7 @@ content = contentResolution.value | ||
if (this.constructor.getTitle) { | ||
let titleResolution = this.resolver.resolve(this.env, this.constructor.getTitle) | ||
let titleResolution = this.resolver.resolve( | ||
this.env, | ||
this.constructor.getTitle, | ||
this.constructor.getMeta | ||
) | ||
resolutionIds.push(titleResolution.id) | ||
@@ -62,14 +87,2 @@ title = titleResolution.value | ||
let meta: Meta | undefined | ||
if (this.constructor.getMeta) { | ||
let metaResolution = this.resolver.resolve(this.env, this.constructor.getMeta) | ||
resolutionIds.push(metaResolution.id) | ||
meta = metaResolution.value | ||
status = reduceStatuses(status, metaResolution.status) | ||
error = error || metaResolution.error | ||
} | ||
else { | ||
meta = this.constructor.meta | ||
} | ||
return { | ||
@@ -91,7 +104,7 @@ resolutionIds: resolutionIds, | ||
title?: string | ||
getTitle?: Resolvable<string> | ||
getTitle?: Resolvable<string, Context, Meta> | ||
meta?: Meta | ||
getMeta?: Resolvable<Meta> | ||
getMeta?: Resolvable<Meta, Context> | ||
content?: Content | ||
getContent?: Resolvable<Content, Context> | ||
getContent?: Resolvable<Content, Context, Meta> | ||
}): Page<Context, Meta, Content> { | ||
@@ -98,0 +111,0 @@ if (process.env.NODE_ENV !== 'production') { |
@@ -5,4 +5,5 @@ import { Env } from './Env' | ||
export type Resolvable<T, Context extends object = any> = ( | ||
export type Resolvable<T, Context extends object = any, Data = any> = ( | ||
env: Env<Context>, | ||
dataPromise: PromiseLike<Data> | ||
) => (T | PromiseLike<{ default: T } | T>) | ||
@@ -13,2 +14,3 @@ | ||
status: Status | ||
promise: PromiseLike<T> | ||
error?: any | ||
@@ -38,3 +40,2 @@ value?: T | ||
private listenerIds: Map<Function, number[]> | ||
private isDisposed: boolean | ||
@@ -45,3 +46,2 @@ constructor() { | ||
this.results = new WeakMap() | ||
this.isDisposed = false | ||
} | ||
@@ -57,5 +57,6 @@ | ||
resolve<T>( | ||
resolve<T, Data>( | ||
env: Env<any>, | ||
resolvable: Resolvable<T>, | ||
dataResolvable?: Resolvable<Data> | ||
): Resolution<T> { | ||
@@ -73,4 +74,7 @@ let matcherResults = this.results.get(env) | ||
let dataResolution = !dataResolvable ? { promise: Promise.resolve() } : ( | ||
matcherResults.get(dataResolvable) || { promise: Promise.resolve() } | ||
) | ||
let id = this.nextId++ | ||
let maybeValue = resolvable(env) | ||
let maybeValue = resolvable(env, dataResolution.promise) | ||
if (!isPromiseLike(maybeValue)) { | ||
@@ -81,2 +85,3 @@ let result: Resolution<T> = { | ||
value: maybeValue, | ||
promise: Promise.resolve(maybeValue), | ||
} | ||
@@ -87,8 +92,10 @@ matcherResults.set(resolvable, result) | ||
let promise = maybeValue.then(extractDefault) | ||
let result: Resolution<T> = { | ||
id, | ||
status: Status.Busy, | ||
promise, | ||
} | ||
matcherResults.set(resolvable, result) | ||
this.listenForChanges(maybeValue, matcherResults, resolvable, id, joinPaths(env.pathname, env.unmatchedPathnamePart)) | ||
this.listenForChanges(promise, matcherResults, resolvable, id, joinPaths(env.pathname, env.unmatchedPathnamePart)) | ||
return result | ||
@@ -98,3 +105,3 @@ } | ||
listenForChanges<T>( | ||
maybeValue: PromiseLike<T>, | ||
promise: PromiseLike<T>, | ||
matcherResults: Map<Function, Resolution<T>>, | ||
@@ -105,3 +112,3 @@ resolvable: Resolvable<T>, | ||
) { | ||
maybeValue | ||
promise | ||
.then( | ||
@@ -114,3 +121,4 @@ value => { | ||
status: Status.Ready, | ||
value: extractDefault(value), | ||
value: value, | ||
promise, | ||
}) | ||
@@ -132,2 +140,3 @@ return true | ||
error: error || new Error(), | ||
promise, | ||
}) | ||
@@ -134,0 +143,0 @@ |
@@ -46,7 +46,7 @@ import { | ||
title?: string | ||
getTitle?: Resolvable<string, Context> | ||
getTitle?: Resolvable<string, Context, Meta> | ||
meta?: Meta | ||
getMeta?: Resolvable<Meta, Context> | ||
content?: Content | ||
getContent?: Resolvable<Content, Context> | ||
getContent?: Resolvable<Content, Context, Meta> | ||
@@ -104,11 +104,30 @@ paths: SwitchPaths<Context> | ||
protected execute(): NodeMatcherResult<SwitchSegment<Meta, Content>> { | ||
let hasContent = this.withContent && this.constructor.getContent | ||
let resolutionIds: number[] = [] | ||
let status: Status = Status.Ready | ||
let error: any | ||
// Meta must come first, as the promise to its result can be used by | ||
// the subsequent resolvables. | ||
let meta: Meta | undefined | ||
if (this.constructor.getMeta) { | ||
let metaResolution = this.resolver.resolve( | ||
this.env, | ||
this.constructor.getMeta | ||
) | ||
resolutionIds.push(metaResolution.id) | ||
meta = metaResolution.value | ||
status = reduceStatuses(status, metaResolution.status) | ||
error = error || metaResolution.error | ||
} | ||
else { | ||
meta = this.constructor.meta | ||
} | ||
let content: Content | undefined | ||
if (this.withContent && this.constructor.getContent) { | ||
let contentResolution = this.resolver.resolve(this.env, this.constructor.getContent) | ||
let contentResolution = this.resolver.resolve( | ||
this.env, | ||
this.constructor.getContent, | ||
this.constructor.getMeta, | ||
) | ||
resolutionIds.push(contentResolution.id) | ||
@@ -125,3 +144,7 @@ content = contentResolution.value | ||
if (this.constructor.getTitle) { | ||
let titleResolution = this.resolver.resolve(this.env, this.constructor.getTitle) | ||
let titleResolution = this.resolver.resolve( | ||
this.env, | ||
this.constructor.getTitle, | ||
this.constructor.getMeta, | ||
) | ||
resolutionIds.push(titleResolution.id) | ||
@@ -135,14 +158,2 @@ title = titleResolution.value | ||
} | ||
let meta: Meta | undefined | ||
if (this.constructor.getMeta) { | ||
let metaResolution = this.resolver.resolve(this.env, this.constructor.getMeta) | ||
resolutionIds.push(metaResolution.id) | ||
meta = metaResolution.value | ||
status = reduceStatuses(status, metaResolution.status) | ||
error = error || metaResolution.error | ||
} | ||
else { | ||
meta = this.constructor.meta | ||
} | ||
@@ -232,7 +243,7 @@ let childMatcher: NodeMatcher<any> | undefined | ||
meta?: Meta | ||
getMeta?: Resolvable<Meta> | ||
getMeta?: Resolvable<Meta, Context> | ||
title?: string | ||
getTitle?: Resolvable<string> | ||
getTitle?: Resolvable<string, Context, Meta> | ||
content?: Content | ||
getContent?: Resolvable<Content, Context> | ||
getContent?: Resolvable<Content, Context, Meta> | ||
}): Switch<Context, Meta, Content> { | ||
@@ -239,0 +250,0 @@ if (!options) { |
@@ -40,11 +40,13 @@ import { createPage, createSwitch, createRedirect, createContext, Env } from '../../src' | ||
getTitle: () => 'Advanced example', | ||
getMeta: () => ({ | ||
getMeta: async () => ({ | ||
isPaywalled: true, | ||
}), | ||
async getContent(env: Env) { | ||
return (env.context.contextName === 'examples' && env.context.isAuthenticated) ? ( | ||
'advanced-example' | ||
) : ( | ||
'please-login' | ||
) | ||
async getContent(env: Env, metaPromise) { | ||
if (env.context.contextName !== 'examples' || !env.context.isAuthenticated) { | ||
return 'please-login' | ||
} | ||
return { | ||
dat: await metaPromise | ||
} | ||
} | ||
@@ -51,0 +53,0 @@ }) |
@@ -58,3 +58,5 @@ import { SwitchSegment, createMemoryNavigation, PageSegment, Status, SegmentType, NotFoundError } from '../src' | ||
expect(pageSegment.content).toBe('advanced-example') | ||
expect(pageSegment.content.dat).toEqual({ | ||
isPaywalled: true, | ||
}) | ||
@@ -61,0 +63,0 @@ nav.history.push('/examples/intermediate') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
691266
13556