main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | var react_1 = require("react");
|
---|
4 | var util_1 = require("./misc/util");
|
---|
5 | // const usePermission = <T extends PermissionDescriptor>(permissionDesc: T): IState => {
|
---|
6 | var usePermission = function (permissionDesc) {
|
---|
7 | var _a = react_1.useState(''), state = _a[0], setState = _a[1];
|
---|
8 | react_1.useEffect(function () {
|
---|
9 | var mounted = true;
|
---|
10 | var permissionStatus = null;
|
---|
11 | var onChange = function () {
|
---|
12 | if (!mounted) {
|
---|
13 | return;
|
---|
14 | }
|
---|
15 | setState(function () { var _a; return (_a = permissionStatus === null || permissionStatus === void 0 ? void 0 : permissionStatus.state) !== null && _a !== void 0 ? _a : ''; });
|
---|
16 | };
|
---|
17 | navigator.permissions
|
---|
18 | .query(permissionDesc)
|
---|
19 | .then(function (status) {
|
---|
20 | permissionStatus = status;
|
---|
21 | util_1.on(permissionStatus, 'change', onChange);
|
---|
22 | onChange();
|
---|
23 | })
|
---|
24 | .catch(util_1.noop);
|
---|
25 | return function () {
|
---|
26 | permissionStatus && util_1.off(permissionStatus, 'change', onChange);
|
---|
27 | mounted = false;
|
---|
28 | permissionStatus = null;
|
---|
29 | };
|
---|
30 | }, [permissionDesc]);
|
---|
31 | return state;
|
---|
32 | };
|
---|
33 | exports.default = usePermission;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.