Browse Source

chore: make Rehydratable use Awaitable; add docblock

master
Garrett Mills 7 months ago
parent
commit
5d960e6186
Signed by: garrettmills GPG Key ID: D2BF5FBA8298F246
  1. 8
      src/event/Event.ts
  2. 8
      src/service/Routing.ts
  3. 7
      src/util/support/Rehydratable.ts

8
src/event/Event.ts

@ -1,11 +1,13 @@
import {Dispatchable} from './types'
import {JSONState} from '../util'
import {Awaitable, JSONState} from '../util'
/**
* Abstract class representing an event that may be fired.
*/
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>
}

8
src/service/Routing.ts

@ -73,6 +73,14 @@ export class Routing extends Unit {
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 {
return this.getAssetBase().concat(...parts)
}

7
src/util/support/Rehydratable.ts

@ -2,6 +2,7 @@
* Type representing a JSON serializable object.
*/
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> }
@ -30,14 +31,14 @@ export function isJSONState(what: unknown): what is JSONState {
export interface Rehydratable {
/**
* 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.
* @param {JSONState} state
* @return void|Promise<void>
*/
rehydrate(state: JSONState): void | Promise<void>
rehydrate(state: JSONState): Awaitable<void>
}

Loading…
Cancel
Save