mobx-keystone
Version:
A MobX powered state management solution based on data trees with first class support for TypeScript, snapshots, patches and much more
38 lines (35 loc) • 908 B
text/typescript
/**
* A hook action.
*/
export enum HookAction {
/**
* onInit hook
*/
OnInit = "$$onInit",
/**
* onLazyInit hook
*/
OnLazyInit = "$$onLazyInit",
/**
* onAttachedToRootStore hook
*/
OnAttachedToRootStore = "$$onAttachedToRootStore",
/**
* disposer for onAttachedToRootStore hook
*/
OnAttachedToRootStoreDisposer = "$$onAttachedToRootStoreDisposer",
}
const hookActionValues: ReadonlySet<string> = new Set(Object.values(HookAction))
/**
* Returns if a given action name corresponds to a hook, this is, one of:
* - onInit() hook
* - onLazyInit() hook
* - onAttachedToRootStore() hook
* - disposer returned by a onAttachedToRootStore() hook
*
* @param actionName Action name to check.
* @returns true if it is a hook, false otherwise.
*/
export function isHookAction(actionName: string): actionName is HookAction {
return hookActionValues.has(actionName)
}