31 lines
713 B
JavaScript
31 lines
713 B
JavaScript
import { useStore } from 'stores/hooks';
|
|
import { useDebouncedCallback } from 'use-debounce';
|
|
|
|
export function useValue(valueName) {
|
|
const { $calculation } = useStore();
|
|
const value = $calculation.$values.getValue(valueName);
|
|
|
|
return value;
|
|
}
|
|
|
|
export function useSetValue(valueName) {
|
|
const { $calculation } = useStore();
|
|
|
|
const debouncedSetStoreValue = useDebouncedCallback(
|
|
(value) => $calculation.$values.setValue(valueName, value),
|
|
350,
|
|
{
|
|
maxWait: 1500,
|
|
}
|
|
);
|
|
|
|
return debouncedSetStoreValue;
|
|
}
|
|
|
|
export function useComputedValue(valueName) {
|
|
const { $calculation } = useStore();
|
|
const computedValue = $calculation.$values.$computed[valueName];
|
|
|
|
return computedValue;
|
|
}
|