You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
900 B
37 lines
900 B
/**
|
|
* Type representing a JSON serializable object.
|
|
*/
|
|
export type JSONState = { [key: string]: string | boolean | number | undefined | JSONState | Array<string | boolean | number | undefined | JSONState> }
|
|
|
|
/**
|
|
* Returns true if the given object can be JSON serialized.
|
|
* @param what
|
|
* @return boolean
|
|
*/
|
|
export function isJSONState(what: any): what is JSONState {
|
|
try {
|
|
JSON.stringify(what)
|
|
return true
|
|
} catch (e) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Base interface for a class that can be rehydrated and restored.
|
|
*/
|
|
export interface Rehydratable {
|
|
/**
|
|
* Dehydrate this class' state and get it.
|
|
* @return Promise<JSONState>
|
|
*/
|
|
dehydrate(): Promise<JSONState>
|
|
|
|
/**
|
|
* Rehydrate a state into this class.
|
|
* @param {JSONState} state
|
|
* @return void|Promise<void>
|
|
*/
|
|
rehydrate(state: JSONState): void | Promise<void>
|
|
}
|