From b882d9afee944977fcc85afe22043bb8ce9f6696 Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Fri, 2 Apr 2021 18:14:10 -0400 Subject: [PATCH 1/4] Remove symbol-observable and loose-envify deps --- package-lock.json | 9 +++------ package.json | 7 ------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index e4462bfb49..8670b47592 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7073,7 +7073,8 @@ "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", - "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=" + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", + "dev": true }, "js-yaml": { "version": "3.14.1", @@ -7296,6 +7297,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "dev": true, "requires": { "js-tokens": "^3.0.0 || ^4.0.0" } @@ -9508,11 +9510,6 @@ } } }, - "symbol-observable": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-2.0.3.tgz", - "integrity": "sha512-sQV7phh2WCYAn81oAkakC5qjq2Ml0g8ozqz03wOGnx9dDlG1de6yrF+0RAzSJD8fPUow3PTSMf2SAbOGxb93BA==" - }, "symbol-tree": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", diff --git a/package.json b/package.json index a57914cae3..59ec76e0d3 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,6 @@ "examples:test": "cross-env CI=true babel-node examples/testAll.js" }, "dependencies": { - "loose-envify": "^1.4.0", - "symbol-observable": "^2.0.3", "@babel/runtime": "^7.9.2" }, "devDependencies": { @@ -102,11 +100,6 @@ ] } ], - "browserify": { - "transform": [ - "loose-envify" - ] - }, "jest": { "testRegex": "(/test/.*\\.spec\\.[tj]s)$", "coverageProvider": "v8" From 0d7d94d8181ff2e6482d8884360726bd098458ba Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Fri, 2 Apr 2021 18:26:48 -0400 Subject: [PATCH 2/4] Inline the symbol-observable polyfill --- index.d.ts | 8 ++++++-- src/createStore.js | 2 +- src/utils/symbol-observable.js | 3 +++ test/createStore.spec.js | 7 +++++-- test/typescript/store.ts | 3 ++- 5 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 src/utils/symbol-observable.js diff --git a/index.d.ts b/index.d.ts index b00c6f0885..a4c47b41ee 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,3 @@ -/// - /** * An *action* is a plain object that represents an intention to change the * state. Actions are the only way to get data into the store. Any data, @@ -224,6 +222,12 @@ export interface Unsubscribe { (): void } +declare global { + interface SymbolConstructor { + readonly observable: symbol; + } +} + /** * A minimal observable of state changes. * For more information, see the observable proposal: diff --git a/src/createStore.js b/src/createStore.js index 5326a52ff8..5e64e323d1 100644 --- a/src/createStore.js +++ b/src/createStore.js @@ -1,4 +1,4 @@ -import $$observable from 'symbol-observable' +import $$observable from './utils/symbol-observable' import ActionTypes from './utils/actionTypes' import isPlainObject from './utils/isPlainObject' diff --git a/src/utils/symbol-observable.js b/src/utils/symbol-observable.js new file mode 100644 index 0000000000..0fb198c986 --- /dev/null +++ b/src/utils/symbol-observable.js @@ -0,0 +1,3 @@ +// Inlined version of the `symbol-observable` polyfill +export default (() => + (typeof Symbol === 'function' && Symbol.observable) || '@@observable')() diff --git a/test/createStore.spec.js b/test/createStore.spec.js index dcbf65cf3e..a1f9cd9125 100644 --- a/test/createStore.spec.js +++ b/test/createStore.spec.js @@ -11,13 +11,16 @@ import { import * as reducers from './helpers/reducers' import { from } from 'rxjs' import { map } from 'rxjs/operators' -import $$observable from 'symbol-observable' +import $$observable from '../src/utils/symbol-observable' describe('createStore', () => { it('exposes the public API', () => { const store = createStore(combineReducers(reducers)) - const methods = Object.keys(store) + // Since switching to internal Symbol.observable impl, it will show up as a key in node env + // So we filter it out + const methods = Object.keys(store).filter(key => key !== $$observable) + expect(methods.length).toBe(4) expect(methods).toContain('subscribe') expect(methods).toContain('dispatch') diff --git a/test/typescript/store.ts b/test/typescript/store.ts index 685bfbf1b6..2d66396887 100644 --- a/test/typescript/store.ts +++ b/test/typescript/store.ts @@ -9,7 +9,8 @@ import { Unsubscribe, Observer, } from 'redux' -import 'symbol-observable' +// @ts-ignore +import $$observable from '../src/utils/symbol-observable' type BrandedString = string & { _brand: 'type' } const brandedString = 'a string' as BrandedString From fb5abcccc2e4c9b36d1459504ed0bd289ddbc930 Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Fri, 2 Apr 2021 18:31:00 -0400 Subject: [PATCH 3/4] Formatting --- index.d.ts | 2 +- test/createStore.spec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index a4c47b41ee..4a4d4e0ad5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -224,7 +224,7 @@ export interface Unsubscribe { declare global { interface SymbolConstructor { - readonly observable: symbol; + readonly observable: symbol } } diff --git a/test/createStore.spec.js b/test/createStore.spec.js index a1f9cd9125..5ed9246bdc 100644 --- a/test/createStore.spec.js +++ b/test/createStore.spec.js @@ -19,8 +19,8 @@ describe('createStore', () => { // Since switching to internal Symbol.observable impl, it will show up as a key in node env // So we filter it out - const methods = Object.keys(store).filter(key => key !== $$observable) - + const methods = Object.keys(store).filter((key) => key !== $$observable) + expect(methods.length).toBe(4) expect(methods).toContain('subscribe') expect(methods).toContain('dispatch') From d29cbfaf5711aaa773ec9d107c4d2578c6b2a59c Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Fri, 2 Apr 2021 18:37:22 -0400 Subject: [PATCH 4/4] Include ESM .mjs file in size comparisons --- .github/workflows/size.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/size.yaml b/.github/workflows/size.yaml index 5c2d03985b..d9aa4474dc 100644 --- a/.github/workflows/size.yaml +++ b/.github/workflows/size.yaml @@ -14,4 +14,4 @@ jobs: - uses: preactjs/compressed-size-action@v1 with: repo-token: '${{ secrets.GITHUB_TOKEN }}' - pattern: './{dist,es,lib}/*.js' + pattern: './{dist,es,lib}/*.{js,mjs}'