-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP-split-current-code-into-a-core-and-implementation-packages
- Loading branch information
Showing
30 changed files
with
7,132 additions
and
2,026 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,7 @@ | |
/coverage | ||
|
||
# production | ||
/build | ||
/dist | ||
dist/ | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"packages": [ | ||
"packages/*" | ||
], | ||
"version": "0.0.0" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# `core-adaptive-hooks` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the 'License'); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an 'AS IS' BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
module.exports = { | ||
presets: [ | ||
"@babel/preset-env" | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export { useNetworkStatus } from './network'; | ||
export { useCoreNetworkStatus } from './network'; | ||
export { useCoreMediaCapabilitiesDecodingInfo } from './media-capabilities'; | ||
|
||
export { useSaveData } from './save-data'; | ||
export { useMemoryStatus } from './memory'; | ||
export { useHardwareConcurrency } from './hardware-concurrency'; | ||
export { useMediaCapabilitiesDecodingInfo } from './media-capabilities'; |
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions
39
packages/core-adaptive-hooks/lib/media-capabilities/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const isMediaCapabilitiesSupported = () => typeof navigator !== 'undefined' && 'mediaCapabilities' in navigator; | ||
|
||
const useCoreMediaCapabilitiesDecodingInfo = async mediaDecodingConfig => { | ||
const supported = isMediaCapabilitiesSupported(); | ||
|
||
if (!supported) { | ||
return {}; | ||
} | ||
|
||
let decodingInfo; | ||
|
||
try { | ||
decodingInfo = await navigator | ||
.mediaCapabilities | ||
.decodingInfo(mediaDecodingConfig); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
|
||
return decodingInfo | ||
}; | ||
|
||
export { isMediaCapabilitiesSupported, useCoreMediaCapabilitiesDecodingInfo }; |
77 changes: 77 additions & 0 deletions
77
packages/core-adaptive-hooks/lib/media-capabilities/media-capabilities.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the 'License'); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an 'AS IS' BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import 'babel-polyfill'; | ||
|
||
const mediaDecodingConfig = { | ||
type: 'file', | ||
audio: { | ||
contentType: 'audio/mp3', | ||
channels: 2, | ||
bitrate: 132700, | ||
samplerate: 5200 | ||
} | ||
}; | ||
|
||
const mediaCapabilitiesMapper = { | ||
'audio/mp3': { | ||
powerEfficient: true, | ||
smooth: true, | ||
supported: true | ||
} | ||
}; | ||
|
||
describe('useMediaCapabilitiesDecodingInfo', () => { | ||
test('should return {} on unsupported platforms', async () => { | ||
const { useCoreMediaCapabilitiesDecodingInfo } = require('./'); | ||
|
||
const result = await useCoreMediaCapabilitiesDecodingInfo(); | ||
|
||
expect(result).toStrictEqual({}); | ||
}); | ||
|
||
test('should return {} on unsupported platforms with config given', async () => { | ||
const { useCoreMediaCapabilitiesDecodingInfo } = require('./'); | ||
const result = await useCoreMediaCapabilitiesDecodingInfo(mediaDecodingConfig); | ||
|
||
expect(result).toStrictEqual({}); | ||
}); | ||
|
||
test('should return mediaCapabilitiesInfo for given media configuration', async () => { | ||
const originalError = console.error; | ||
console.error = jest.fn(); | ||
|
||
const mockDecodingInfo = jest.fn().mockImplementation(() => Promise.resolve({ | ||
...mediaCapabilitiesMapper[mediaDecodingConfig.audio.contentType] | ||
})); | ||
|
||
global.navigator.mediaCapabilities = { | ||
decodingInfo: mockDecodingInfo | ||
}; | ||
|
||
const { useCoreMediaCapabilitiesDecodingInfo } = require('./'); | ||
|
||
try { | ||
const result = await useCoreMediaCapabilitiesDecodingInfo(mediaDecodingConfig); | ||
|
||
expect(result.powerEfficient).toEqual(true); | ||
expect(result.smooth).toEqual(true); | ||
expect(result.supported).toEqual(true); | ||
} finally { | ||
console.error = originalError; | ||
} | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the 'License'); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an 'AS IS' BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const isNetworkStatusSupported = () => typeof navigator !== 'undefined' && 'connection' in navigator && 'effectiveType' in navigator.connection; | ||
|
||
const useCoreNetworkStatus = () => { | ||
const navigatorConnection = navigator.connection; | ||
|
||
return isNetworkStatusSupported() ? | ||
{ | ||
effectiveConnectionType: navigatorConnection.effectiveType | ||
} : | ||
{} | ||
}; | ||
|
||
export { isNetworkStatusSupported, useCoreNetworkStatus }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the 'License'); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an 'AS IS' BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { useCoreNetworkStatus } from './'; | ||
|
||
describe('useCoreNetworkStatus', () => { | ||
test(`should return "{}" for unsupported case`, () => { | ||
const result = useCoreNetworkStatus(); | ||
|
||
expect(result).toStrictEqual({}); | ||
}); | ||
|
||
test('should return 4g of effectiveConnectionType', () => { | ||
global.navigator.connection = { | ||
effectiveType: '4g' | ||
}; | ||
|
||
const result = useCoreNetworkStatus(); | ||
|
||
const expectedConnection = { | ||
effectiveConnectionType: '4g' | ||
}; | ||
|
||
expect(result).toStrictEqual(expectedConnection); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "core-adaptive-hooks", | ||
"version": "0.0.1", | ||
"description": "core adaptive hooks", | ||
"keywords": [ | ||
"adaptive-hooks" | ||
], | ||
"author": "Google Chrome", | ||
"homepage": "https://github.com/GoogleChromeLabs/react-adaptive-hooks#readme", | ||
"license": "Apache-2.0", | ||
"extends": "../../babel.config.js", | ||
"main": "dist/index.js", | ||
"module": "dist/index.module.js", | ||
"unpkg": "dist/index.umd.js", | ||
"source": "lib/core-adaptive-hooks.js", | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.5.5", | ||
"babel-polyfill": "^6.26.0", | ||
"jest": "^24.8.0", | ||
"lerna": "^3.22.1", | ||
"microbundle": "0.11.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/GoogleChromeLabs/react-adaptive-hooks.git" | ||
}, | ||
"scripts": { | ||
"build": "microbundle", | ||
"dev": "microbundle watch", | ||
"prepare": "npm run build", | ||
"test": "jest", | ||
"test:coverage": "jest --coverage" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/GoogleChromeLabs/react-adaptive-hooks/issues" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# `react-adaptive-hooks` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the 'License'); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an 'AS IS' BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
module.exports = { | ||
presets: [ | ||
"@babel/preset-env" | ||
] | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export { useSaveData } from '../../core-adaptive-hooks/lib/save-data'; | ||
export { useMemoryStatus } from '../../core-adaptive-hooks/lib/memory'; | ||
export { useHardwareConcurrency } from '../../core-adaptive-hooks/lib/hardware-concurrency'; | ||
|
||
export { useNetworkStatus } from './network'; | ||
export { useMediaCapabilitiesDecodingInfo } from './media-capabilities'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "react-adaptive-hooks", | ||
"version": "0.0.1", | ||
"description": "react adaptive hooks", | ||
"keywords": [ | ||
"adaptive-hooks" | ||
], | ||
"author": "Google Chrome", | ||
"homepage": "https://github.com/GoogleChromeLabs/react-adaptive-hooks#readme", | ||
"license": "Apache-2.0", | ||
"main": "dist/index.js", | ||
"module": "dist/index.module.js", | ||
"unpkg": "dist/index.umd.js", | ||
"source": "lib/react-adaptive-hooks.js", | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"peerDependencies": { | ||
"react": "^16.8.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.5.5", | ||
"@testing-library/react-hooks": "^1.1.0", | ||
"babel-polyfill": "^6.26.0", | ||
"jest": "^24.8.0", | ||
"lerna": "^3.22.1", | ||
"microbundle": "0.11.0", | ||
"react": "16.9.0", | ||
"react-test-renderer": "16.9.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/GoogleChromeLabs/react-adaptive-hooks.git" | ||
}, | ||
"scripts": { | ||
"build": "microbundle", | ||
"dev": "microbundle watch", | ||
"prepare": "npm run build", | ||
"test": "jest", | ||
"test:coverage": "jest --coverage" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/GoogleChromeLabs/react-adaptive-hooks/issues" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# `vue-adaptive-hooks` |
Oops, something went wrong.