[IMP] hooks: add some building blocks for hooks

This commit introduces two new hooks: useComponent, and
useEnv.
This commit is contained in:
Géry Debongnie
2020-12-03 13:45:39 +01:00
committed by aab-odoo
parent 2a53a9592e
commit 9a87b9a4a0
4 changed files with 65 additions and 5 deletions
+21 -1
View File
@@ -1,4 +1,4 @@
import { Component } from "./component/component";
import { Component, Env } from "./component/component";
import { Observer } from "./core/observer";
/**
@@ -118,6 +118,26 @@ export function useRef<C extends Component = Component>(name: string): Ref<C> {
};
}
// -----------------------------------------------------------------------------
// "Builder" hooks
// -----------------------------------------------------------------------------
/**
* This hook is useful as a building block for some customized hooks, that may
* need a reference to the component calling them.
*/
export function useComponent<P, E extends Env>(): Component<P, E> {
return Component.current as any;
}
/**
* This hook is useful as a building block for some customized hooks, that may
* need a reference to the env of the component calling them.
*/
export function useEnv<E extends Env>(): E {
return Component.current.env as any;
}
// -----------------------------------------------------------------------------
// useSubEnv
// -----------------------------------------------------------------------------