chore: make Rehydratable use Awaitable; add docblock

This commit is contained in:
Garrett Mills 2021-07-02 21:44:34 -05:00
parent cf6d14abca
commit 5d960e6186
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
3 changed files with 17 additions and 6 deletions

View File

@ -1,11 +1,13 @@
import {Dispatchable} from './types' import {Dispatchable} from './types'
import {JSONState} from '../util' import {Awaitable, JSONState} from '../util'
/** /**
* Abstract class representing an event that may be fired. * Abstract class representing an event that may be fired.
*/ */
export abstract class Event implements Dispatchable { export abstract class Event implements Dispatchable {
abstract dehydrate(): Promise<JSONState>
abstract rehydrate(state: JSONState): void | Promise<void>
abstract dehydrate(): Awaitable<JSONState>
abstract rehydrate(state: JSONState): Awaitable<void>
} }

View File

@ -73,6 +73,14 @@ export class Routing extends Unit {
return this.compiledRoutes return this.compiledRoutes
} }
/**
* Resolve a UniversalPath to a file served as an asset.
* @example
* ```ts
* this.getAssetPath('images', '123.jpg').toRemote // => http://localhost:8000/assets/images/123.jpg
* ```
* @param parts
*/
public getAssetPath(...parts: string[]): UniversalPath { public getAssetPath(...parts: string[]): UniversalPath {
return this.getAssetBase().concat(...parts) return this.getAssetBase().concat(...parts)
} }

View File

@ -2,6 +2,7 @@
* Type representing a JSON serializable object. * Type representing a JSON serializable object.
*/ */
import {ErrorWithContext} from '../error/ErrorWithContext' import {ErrorWithContext} from '../error/ErrorWithContext'
import {Awaitable} from './types'
export type JSONState = { [key: string]: string | boolean | number | undefined | JSONState | Array<string | boolean | number | undefined | JSONState> } export type JSONState = { [key: string]: string | boolean | number | undefined | JSONState | Array<string | boolean | number | undefined | JSONState> }
@ -30,14 +31,14 @@ export function isJSONState(what: unknown): what is JSONState {
export interface Rehydratable { export interface Rehydratable {
/** /**
* Dehydrate this class' state and get it. * Dehydrate this class' state and get it.
* @return Promise<JSONState> * @return JSONState|Promise<JSONState>
*/ */
dehydrate(): Promise<JSONState> dehydrate(): Awaitable<JSONState>
/** /**
* Rehydrate a state into this class. * Rehydrate a state into this class.
* @param {JSONState} state * @param {JSONState} state
* @return void|Promise<void> * @return void|Promise<void>
*/ */
rehydrate(state: JSONState): void | Promise<void> rehydrate(state: JSONState): Awaitable<void>
} }