@webitel/ui-sdk 3.2.131 → 3.2.133

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/ui-sdk",
3
- "version": "3.2.131",
3
+ "version": "3.2.133",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve-lib": "vue-cli-service serve",
@@ -0,0 +1,14 @@
1
+ import { useCachedInterval } from '../useCachedInterval';
2
+
3
+ describe('useCachedInterval', () => {
4
+ it('subscribe', (done) => {
5
+ const callback = jest.fn();
6
+ const { subscribe } = useCachedInterval({ timeout: 10 });
7
+ subscribe(callback);
8
+ expect(callback).toHaveBeenCalledTimes(1);
9
+ setTimeout(() => {
10
+ expect(callback).toHaveBeenCalledTimes(2);
11
+ done();
12
+ }, 10);
13
+ });
14
+ });
@@ -0,0 +1,21 @@
1
+ import { onBeforeUnmount } from 'vue';
2
+ import preventHiddenPageCallsDecorator
3
+ from '../../scripts/preventHiddenPageCallsDecorator';
4
+
5
+ // eslint-disable-next-line import/prefer-default-export
6
+ export const useCachedInterval = ({
7
+ timeout,
8
+ localStorageKey = 'auto-refresh',
9
+ }) => {
10
+ let interval = null;
11
+
12
+ onBeforeUnmount(() => {
13
+ if (interval) clearInterval(interval);
14
+ });
15
+ const subscribe = (callback) => {
16
+ const _timeout = timeout || +localStorage.getItem(localStorageKey) || 5 * 60 * 1000;
17
+ callback();
18
+ interval = setInterval(preventHiddenPageCallsDecorator(callback), _timeout);
19
+ };
20
+ return { subscribe };
21
+ };
Binary file
@@ -0,0 +1,27 @@
1
+ import BaseStoreModule from '../BaseStoreModules/BaseStoreModule';
2
+
3
+ let interval = null;
4
+
5
+ export default class ReactiveNowStoreModule extends BaseStoreModule {
6
+ state = {
7
+ now: Date.now(),
8
+ };
9
+
10
+ actions = {
11
+ SET_NOW_WATCHER: (context) => {
12
+ interval = setInterval(() => {
13
+ context.commit('UPDATE_NOW');
14
+ }, 1000);
15
+ },
16
+
17
+ CLEAR_NOW_WATCHER: () => {
18
+ clearInterval(interval);
19
+ },
20
+ };
21
+
22
+ mutations = {
23
+ UPDATE_NOW: (state) => {
24
+ state.now = Date.now();
25
+ },
26
+ };
27
+ }