mirror of
https://github.com/nasa/openmct.git
synced 2024-12-22 06:27:48 +00:00
add useClockOffsets composable
documentation update to useTimeBounds
This commit is contained in:
parent
15126fd550
commit
e624821ab1
59
src/plugins/timeConductor/useClockOffsets.js
Normal file
59
src/plugins/timeConductor/useClockOffsets.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2024, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
import { onBeforeUnmount, shallowRef } from 'vue';
|
||||||
|
|
||||||
|
import { TIME_CONTEXT_EVENTS } from '../../api/time/constants.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides reactive `offsets`,
|
||||||
|
* as well as a function to observe and update offsets changes,
|
||||||
|
* which automatically stops observing when the component is unmounted.
|
||||||
|
*
|
||||||
|
* @param {OpenMCT} openmct the Open MCT API
|
||||||
|
* @returns {{
|
||||||
|
* observeClockOffsets: () => void,
|
||||||
|
* offsets: import('vue').Ref<object>,
|
||||||
|
* }}
|
||||||
|
*/
|
||||||
|
export function useClockOffsets(openmct, options) {
|
||||||
|
let stopObservingClockOffsets;
|
||||||
|
|
||||||
|
const offsets = shallowRef(openmct.time.getClockOffsets());
|
||||||
|
|
||||||
|
onBeforeUnmount(() => stopObservingClockOffsets?.());
|
||||||
|
|
||||||
|
function observeClockOffsets() {
|
||||||
|
openmct.time.on(TIME_CONTEXT_EVENTS.clockOffsetsChanged, updateClockOffsets);
|
||||||
|
stopObservingClockOffsets = () =>
|
||||||
|
openmct.time.off(TIME_CONTEXT_EVENTS.clockOffsetsChanged, updateClockOffsets);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateClockOffsets(_offsets) {
|
||||||
|
offsets.value = _offsets;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
observeClockOffsets,
|
||||||
|
offsets
|
||||||
|
};
|
||||||
|
}
|
@ -26,8 +26,8 @@ import { TIME_CONTEXT_EVENTS } from '../../api/time/constants.js';
|
|||||||
import throttle from '../../utils/throttle.js';
|
import throttle from '../../utils/throttle.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides reactive `bounds` and `offsets`,
|
* Provides reactive `bounds`,
|
||||||
* as well as a function to observe when bounds and update the component's time mode,
|
* as well as a function to observe and update bounds changes,
|
||||||
* which automatically stops observing when the component is unmounted.
|
* which automatically stops observing when the component is unmounted.
|
||||||
*
|
*
|
||||||
* @param {OpenMCT} openmct the Open MCT API
|
* @param {OpenMCT} openmct the Open MCT API
|
||||||
|
Loading…
Reference in New Issue
Block a user