From dc264ec50ca3208d940521bdac0b61352d913c95 Mon Sep 17 00:00:00 2001 From: infiinte-persistence Date: Wed, 1 Sep 2021 09:59:00 +0800 Subject: [PATCH] Fix Object.fromEntries crash on some browsers ## Issue 6985 fromentries app crash - fix or add polyfill --- dist/bundle.es.js | 11 +++++++---- dist/flow-typed/npm/from-entries.js | 5 +++++ flow-typed/npm/from-entries.js | 5 +++++ package.json | 1 + src/redux/selectors/collections.js | 9 +++++---- yarn.lock | 5 +++++ 6 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 dist/flow-typed/npm/from-entries.js create mode 100644 flow-typed/npm/from-entries.js diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 12358cb..7a11b56 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -2,9 +2,12 @@ Object.defineProperty(exports, '__esModule', { value: true }); +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } + require('proxy-polyfill'); var uuid = require('uuid'); var reselect = require('reselect'); +var fromEntries = _interopDefault(require('@ungap/from-entries')); const MINIMUM_PUBLISH_BID = 0.00000001; @@ -3648,7 +3651,7 @@ const makeSelectCollectionIsMine = id => reselect.createSelector(selectMyCollect const selectMyPublishedCollections = reselect.createSelector(selectResolvedCollections, selectPendingCollections, selectMyEditedCollections, selectMyCollectionIds, (resolved, pending, edited, myIds) => { // all resolved in myIds, plus those in pending and edited - const myPublishedCollections = Object.fromEntries(Object.entries(pending).concat(Object.entries(resolved).filter(([key, val]) => myIds.includes(key) && + const myPublishedCollections = fromEntries(Object.entries(pending).concat(Object.entries(resolved).filter(([key, val]) => myIds.includes(key) && // $FlowFixMe !pending[key]))); // now add in edited: @@ -3659,7 +3662,7 @@ const selectMyPublishedCollections = reselect.createSelector(selectResolvedColle }); const selectMyPublishedMixedCollections = reselect.createSelector(selectMyPublishedCollections, published => { - const myCollections = Object.fromEntries( + const myCollections = fromEntries( // $FlowFixMe Object.entries(published).filter(([key, collection]) => { // $FlowFixMe @@ -3669,7 +3672,7 @@ const selectMyPublishedMixedCollections = reselect.createSelector(selectMyPublis }); const selectMyPublishedPlaylistCollections = reselect.createSelector(selectMyPublishedCollections, published => { - const myCollections = Object.fromEntries( + const myCollections = fromEntries( // $FlowFixMe Object.entries(published).filter(([key, collection]) => { // $FlowFixMe @@ -3684,7 +3687,7 @@ const makeSelectMyPublishedCollectionForId = id => reselect.createSelector(selec // selectResolvedCollections, // selectSavedCollectionIds, // (resolved, myIds) => { -// const mySavedCollections = Object.fromEntries( +// const mySavedCollections = fromEntries( // Object.entries(resolved).filter(([key, val]) => myIds.includes(key)) // ); // return mySavedCollections; diff --git a/dist/flow-typed/npm/from-entries.js b/dist/flow-typed/npm/from-entries.js new file mode 100644 index 0000000..ce92b81 --- /dev/null +++ b/dist/flow-typed/npm/from-entries.js @@ -0,0 +1,5 @@ +// @flow + +declare module '@ungap/from-entries' { + declare module.exports: any; +} diff --git a/flow-typed/npm/from-entries.js b/flow-typed/npm/from-entries.js new file mode 100644 index 0000000..ce92b81 --- /dev/null +++ b/flow-typed/npm/from-entries.js @@ -0,0 +1,5 @@ +// @flow + +declare module '@ungap/from-entries' { + declare module.exports: any; +} diff --git a/package.json b/package.json index 00a2b2a..dc6bc25 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "test": "jest" }, "dependencies": { + "@ungap/from-entries": "^0.2.1", "proxy-polyfill": "0.1.6", "reselect": "^3.0.0", "uuid": "^8.3.1" diff --git a/src/redux/selectors/collections.js b/src/redux/selectors/collections.js index 6eb68c9..371a28d 100644 --- a/src/redux/selectors/collections.js +++ b/src/redux/selectors/collections.js @@ -1,4 +1,5 @@ // @flow +import fromEntries from '@ungap/from-entries'; import { createSelector } from 'reselect'; import { selectMyCollectionIds, @@ -79,7 +80,7 @@ export const selectMyPublishedCollections = createSelector( selectMyCollectionIds, (resolved, pending, edited, myIds) => { // all resolved in myIds, plus those in pending and edited - const myPublishedCollections = Object.fromEntries( + const myPublishedCollections = fromEntries( Object.entries(pending).concat( Object.entries(resolved).filter( ([key, val]) => @@ -100,7 +101,7 @@ export const selectMyPublishedCollections = createSelector( export const selectMyPublishedMixedCollections = createSelector( selectMyPublishedCollections, published => { - const myCollections = Object.fromEntries( + const myCollections = fromEntries( // $FlowFixMe Object.entries(published).filter(([key, collection]) => { // $FlowFixMe @@ -114,7 +115,7 @@ export const selectMyPublishedMixedCollections = createSelector( export const selectMyPublishedPlaylistCollections = createSelector( selectMyPublishedCollections, published => { - const myCollections = Object.fromEntries( + const myCollections = fromEntries( // $FlowFixMe Object.entries(published).filter(([key, collection]) => { // $FlowFixMe @@ -135,7 +136,7 @@ export const makeSelectMyPublishedCollectionForId = (id: string) => // selectResolvedCollections, // selectSavedCollectionIds, // (resolved, myIds) => { -// const mySavedCollections = Object.fromEntries( +// const mySavedCollections = fromEntries( // Object.entries(resolved).filter(([key, val]) => myIds.includes(key)) // ); // return mySavedCollections; diff --git a/yarn.lock b/yarn.lock index 3a5974d..af93714 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1411,6 +1411,11 @@ dependencies: "@types/yargs-parser" "*" +"@ungap/from-entries@^0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@ungap/from-entries/-/from-entries-0.2.1.tgz#7e86196b8b2e99d73106a8f25c2a068326346354" + integrity sha512-CAqefTFAfnUPwYqsWHXpOxHaq1Zo5UQ3m9Zm2p09LggGe57rqHoBn3c++xcoomzXKynAUuiBMDUCQvKMnXjUpA== + abab@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e"