• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alovajs / alova / #210

08 Oct 2024 07:26AM CUT coverage: 93.734% (-0.09%) from 93.826%
#210

push

github

web-flow
Merge pull request #554 from alovajs/changeset-release/main

ci: release

1608 of 1761 branches covered (91.31%)

Branch coverage included in aggregate %.

9537 of 10129 relevant lines covered (94.16%)

60.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.6
/packages/client/src/statesHook/vue.ts
1
import { createSyncOnceRunner } from '@alova/shared/function';
1✔
2
import { forEach, setTimeoutFn, trueValue } from '@alova/shared/vars';
1✔
3
import { StatesHook } from 'alova';
1✔
4
import { computed, getCurrentInstance, onMounted, onUnmounted, ref, watch } from 'vue';
1✔
5
import { VueHookExportType } from '~/typings/stateshook/vue';
1✔
6

1✔
7
// Vue的预定义hooks
1✔
8
export default {
1✔
9
  name: 'Vue',
1✔
10
  create: data => ref(data),
1✔
11
  dehydrate: state => state.value,
1✔
12
  update: (newVal, state) => {
1✔
13
    state.value = newVal;
132✔
14
  },
1✔
15
  effectRequest({ handler, removeStates, immediate, watchingStates }) {
1✔
16
    // 当在组件内部使用时,组件卸载时移除对应状态
46✔
17
    if (getCurrentInstance()) {
46!
18
      onUnmounted(removeStates);
×
19
      onMounted(() => immediate && handler());
×
20
    } else {
46✔
21
      // 在非组件内部使用时,使用定时器延迟执行
46✔
22
      setTimeoutFn(() => {
46✔
23
        immediate && handler();
46✔
24
      });
46✔
25
    }
46✔
26

46✔
27
    const syncRunner = createSyncOnceRunner();
46✔
28
    forEach(watchingStates || [], (state, i) => {
46✔
29
      watch(
37✔
30
        state,
37✔
31
        () => {
37✔
32
          syncRunner(() => {
56✔
33
            handler(i);
32✔
34
          });
56✔
35
        },
37✔
36
        { deep: trueValue }
37✔
37
      );
37✔
38
    });
46✔
39
  },
1✔
40
  computed: getter => computed(getter),
1✔
41
  watch: (states, callback) => {
1✔
42
    watch(states, callback, {
×
43
      deep: trueValue
×
44
    });
×
45
  },
1✔
46
  onMounted: callback => {
1✔
47
    if (getCurrentInstance()) {
×
48
      onMounted(callback);
×
49
    } else {
×
50
      setTimeoutFn(callback, 10);
×
51
    }
×
52
  },
1✔
53
  onUnmounted: callback => {
1✔
54
    getCurrentInstance() && onUnmounted(callback);
×
55
  }
×
56
} as StatesHook<VueHookExportType<unknown>>;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc