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

miaoxing / admin / 6361013200

30 Sep 2023 06:25AM UTC coverage: 28.947%. Remained the same
6361013200

push

github

twinh
feat(admin): `useOption` 支持多个同时调用时,只发送一个请求

22 of 87 branches covered (0.0%)

1 of 9 new or added lines in 1 file covered. (11.11%)

4 existing lines in 1 file now uncovered.

165 of 570 relevant lines covered (28.95%)

2.1 hits per line

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

12.5
/modules/use-option.js
1
import {useState} from 'react';
2
import useAsyncEffect from 'use-async-effect';
3
import api from '@mxjs/api';
4
import $ from 'miaoxing';
5
import memoizeOne from 'async-memoize-one';
6

7
async function getOption (name) {
NEW
8
  const {ret} = await api.get('options', {params: {id: name}});
×
NEW
9
  if (ret.isErr()) {
×
NEW
10
    $.ret(ret);
×
NEW
11
    return;
×
12
  }
NEW
13
  return ret.data;
×
14
}
15

16
const getOptionFromCache = memoizeOne(name => getOption(name));
3✔
17

18
/**
19
 * @experimental
20
 */
21
const useOption = (name, defaults) => {
3✔
22
  if (typeof name !== 'string') {
×
23
    defaults = name;
×
UNCOV
24
    name = Object.keys(name).join(',');
×
25
  }
26

UNCOV
27
  const [value, setValue] = useState(defaults);
×
UNCOV
28
  useAsyncEffect(async () => {
×
NEW
29
    const data = await getOptionFromCache(name);
×
NEW
30
    if (data) {
×
NEW
31
      setValue(data);
×
32
    }
33
  }, [name]);
34

UNCOV
35
  return value;
×
36
};
37

38
export default useOption;
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