Skip to content

Commit

Permalink
fix: bundle NetworkInformation properly
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Mar 30, 2020
1 parent 10f1b48 commit 2839251
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 17 deletions.
7 changes: 0 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
module.exports = {
preset: 'ts-jest',

// TODO: Remove when `network-information-types` become obsolete
transformIgnorePatterns: ['/node_modules/(!network-information-types/)'],
moduleNameMapper: {
'network-information-types':
'network-information-types/dist-types/index.d.ts',
},
};
3 changes: 1 addition & 2 deletions packages/web-api-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"doc": "documentation readme src --section Reference --config documentation.yml --markdown-toc-max-depth 3 --parse-extension ts && prettier --write README.md"
},
"dependencies": {
"@types/resize-observer-browser": "^0.1.2",
"network-information-types": "^0.1.0"
"@types/resize-observer-browser": "^0.1.2"
},
"devDependencies": {
"typescript": "^3.8.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Source: https://github.com/lacolaco/network-information-types/blob/master/index.d.ts

// W3C Spec Draft http://wicg.github.io/netinfo/
// Edition: Draft Community Group Report 20 February 2019

// http://wicg.github.io/netinfo/#connection-types
type ConnectionType =
| 'bluetooth'
| 'cellular'
| 'ethernet'
| 'mixed'
| 'none'
| 'other'
| 'unknown'
| 'wifi'
| 'wimax';

// http://wicg.github.io/netinfo/#effectiveconnectiontype-enum
type EffectiveConnectionType = '2g' | '3g' | '4g' | 'slow-2g';

// http://wicg.github.io/netinfo/#dom-megabit
type Megabit = number;
// http://wicg.github.io/netinfo/#dom-millisecond
type Millisecond = number;

// http://wicg.github.io/netinfo/#networkinformation-interface
export interface NetworkInformation extends EventTarget {
// http://wicg.github.io/netinfo/#type-attribute
readonly type?: ConnectionType;
// http://wicg.github.io/netinfo/#effectivetype-attribute
readonly effectiveType?: EffectiveConnectionType;
// http://wicg.github.io/netinfo/#downlinkmax-attribute
readonly downlinkMax?: Megabit;
// http://wicg.github.io/netinfo/#downlink-attribute
readonly downlink?: Megabit;
// http://wicg.github.io/netinfo/#rtt-attribute
readonly rtt?: Millisecond;
// http://wicg.github.io/netinfo/#savedata-attribute
readonly saveData?: boolean;
// http://wicg.github.io/netinfo/#handling-changes-to-the-underlying-connection
onchange?: EventListener;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Source: https://github.com/lacolaco/network-information-types/blob/master/index.d.ts

// W3C Spec Draft http://wicg.github.io/netinfo/
// Edition: Draft Community Group Report 20 February 2019

// http://wicg.github.io/netinfo/#connection-types
type ConnectionType =
| 'bluetooth'
| 'cellular'
| 'ethernet'
| 'mixed'
| 'none'
| 'other'
| 'unknown'
| 'wifi'
| 'wimax';

// http://wicg.github.io/netinfo/#effectiveconnectiontype-enum
type EffectiveConnectionType = '2g' | '3g' | '4g' | 'slow-2g';

// http://wicg.github.io/netinfo/#dom-megabit
type Megabit = number;
// http://wicg.github.io/netinfo/#dom-millisecond
type Millisecond = number;

// http://wicg.github.io/netinfo/#networkinformation-interface
interface NetworkInformation extends EventTarget {
// http://wicg.github.io/netinfo/#type-attribute
readonly type?: ConnectionType;
// http://wicg.github.io/netinfo/#effectivetype-attribute
readonly effectiveType?: EffectiveConnectionType;
// http://wicg.github.io/netinfo/#downlinkmax-attribute
readonly downlinkMax?: Megabit;
// http://wicg.github.io/netinfo/#downlink-attribute
readonly downlink?: Megabit;
// http://wicg.github.io/netinfo/#rtt-attribute
readonly rtt?: Millisecond;
// http://wicg.github.io/netinfo/#savedata-attribute
readonly saveData?: boolean;
// http://wicg.github.io/netinfo/#handling-changes-to-the-underlying-connection
onchange?: EventListener;
}

// http://wicg.github.io/netinfo/#navigatornetworkinformation-interface
/* eslint-disable @typescript-eslint/no-empty-interface */
declare interface Navigator extends NavigatorNetworkInformation {}
declare interface WorkerNavigator extends NavigatorNetworkInformation {}
/* eslint-enable @typescript-eslint/no-empty-interface */

// http://wicg.github.io/netinfo/#navigatornetworkinformation-interface
declare interface NavigatorNetworkInformation {
readonly connection?: NetworkInformation;
}
4 changes: 1 addition & 3 deletions packages/web-api-hooks/src/useNetworkInformation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// eslint-disable-next-line import/no-unresolved
import 'network-information-types';

import { useEffect, useState } from 'react';

import { NetworkInformation } from './experimental-types/NetworkInformation.bundled';
import { canUseDOM, managedEventListener } from './utils';

/**
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8208,11 +8208,6 @@ neo-async@^2.6.0:
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.1.tgz#ac27ada66167fa8849a6addd837f6b189ad2081c"
integrity sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw==

network-information-types@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/network-information-types/-/network-information-types-0.1.0.tgz#5c880bebc2a9e6b25eb00ed23854d13ff3a7fe3a"
integrity sha512-cRUCYZoRHTMjYcgk5MbwqM0h0Za34panRxAJKY8n+mQ+NLMuRIw7aKzmaZqkC/cte7bnRcdfTwFA27GgN62EtQ==

nice-try@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
Expand Down

0 comments on commit 2839251

Please sign in to comment.