Skip to content

Commit 0971fd3

Browse files
authored
fix: reduce bundle size by limiting external dependencies (#276)
I removed external dependency of `flux-standard-action` that includes entire loadash with it when imported. Instead, I re-implemented single function we are using and relied on single modules from loadash that are required. Should reduce the size significantly
1 parent 5238bce commit 0971fd3

4 files changed

Lines changed: 42 additions & 48 deletions

File tree

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"node": ">= 12"
3535
},
3636
"dependencies": {
37-
"flux-standard-action": "^2.0.0"
37+
"lodash.isplainobject": "^4.0.6",
38+
"lodash.isstring": "^4.0.1"
3839
},
3940
"peerDependencies": {
4041
"electron": ">=8.0.0",
@@ -51,6 +52,8 @@
5152
"@rollup/plugin-commonjs": "^15.0.0",
5253
"@rollup/plugin-node-resolve": "^9.0.0",
5354
"@types/jest": "^26.0.14",
55+
"@types/lodash.isplainobject": "^4.0.6",
56+
"@types/lodash.isstring": "^4.0.6",
5457
"@types/node": "^14.11.1",
5558
"@typescript-eslint/eslint-plugin": "^4.4.0",
5659
"@typescript-eslint/parser": "^4.4.0",

src/utils/actions.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FluxStandardAction, isFSA } from 'flux-standard-action'
1+
import { isFSA, FluxStandardAction } from './isFSA'
22

33
// Certain actions that we should never replay across stores
44
const blacklist = [/^@@/, /^redux-form/]
@@ -12,7 +12,7 @@ type ActionMeta = {
1212
* stopForwarding allows you to give it an action, and it will return an
1313
* equivalent action that will only play in the current process
1414
*/
15-
export const stopForwarding = (action: FluxStandardAction<string, unknown, ActionMeta>) => ({
15+
export const stopForwarding = (action: FluxStandardAction<ActionMeta>) => ({
1616
...action,
1717
meta: {
1818
...action.meta,
@@ -23,11 +23,9 @@ export const stopForwarding = (action: FluxStandardAction<string, unknown, Actio
2323
/**
2424
* validateAction ensures that the action meets the right format and isn't scoped locally
2525
*/
26-
export const validateAction = (
27-
action: unknown
28-
): action is FluxStandardAction<string, unknown, ActionMeta> => {
26+
export const validateAction = (action: any): action is FluxStandardAction<ActionMeta> => {
2927
return (
30-
isFSA<string, unknown, ActionMeta>(action) &&
28+
isFSA(action) &&
3129
action.meta?.scope !== 'local' &&
3230
blacklist.every((rule) => !rule.test(action.type))
3331
)

src/utils/isFSA.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import isPlainObject from 'lodash.isplainobject'
2+
import isString from 'lodash.isstring'
3+
4+
export const isFSA = (action: FluxStandardAction): boolean =>
5+
isPlainObject(action) && isString(action.type) && Object.keys(action).every(isValidKey)
6+
7+
const isValidKey = (key: string) => ['type', 'payload', 'error', 'meta'].indexOf(key) > -1
8+
9+
export type FluxStandardAction<Meta = unknown> = {
10+
type: string
11+
payload?: unknown
12+
meta?: Meta
13+
}

yarn.lock

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,25 @@
16461646
dependencies:
16471647
"@types/node" "*"
16481648

1649+
"@types/lodash.isplainobject@^4.0.6":
1650+
version "4.0.6"
1651+
resolved "https://registry.yarnpkg.com/@types/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#757d2dcdecbb32f4452018b285a586776092efd1"
1652+
integrity sha512-8G41YFhmOl8Ck6NrwLK5hhnbz6ADfuDJP+zusDnX3PoYhfC60+H/rQE6zmdO4yFzPCPJPY4oGZK2spbXm6gYEA==
1653+
dependencies:
1654+
"@types/lodash" "*"
1655+
1656+
"@types/lodash.isstring@^4.0.6":
1657+
version "4.0.6"
1658+
resolved "https://registry.yarnpkg.com/@types/lodash.isstring/-/lodash.isstring-4.0.6.tgz#1534d0c19a2ad79caa17558a298e366893ffd08c"
1659+
integrity sha512-uUGvF9G1G7jQ5H42Y38GA9rZmUoY8wI/OMSwnW0BZA+Ra0uxzpuQf4CixXl3yG3TvF6LjuduMyt1WvKl+je8QA==
1660+
dependencies:
1661+
"@types/lodash" "*"
1662+
1663+
"@types/lodash@*":
1664+
version "4.14.162"
1665+
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.162.tgz#65d78c397e0d883f44afbf1f7ba9867022411470"
1666+
integrity sha512-alvcho1kRUnnD1Gcl4J+hK0eencvzq9rmzvFPRmP5rPHx9VVsJj6bKLTATPVf9ktgv4ujzh7T+XWKp+jhuODig==
1667+
16491668
"@types/minimatch@*":
16501669
version "3.0.3"
16511670
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
@@ -4015,7 +4034,7 @@ debug@^4.0.0:
40154034
dependencies:
40164035
ms "2.1.2"
40174036

4018-
debuglog@*, debuglog@^1.0.1:
4037+
debuglog@^1.0.1:
40194038
version "1.0.1"
40204039
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
40214040
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
@@ -5433,13 +5452,6 @@ flush-write-stream@^1.0.0:
54335452
inherits "^2.0.3"
54345453
readable-stream "^2.3.6"
54355454

5436-
flux-standard-action@^2.0.0:
5437-
version "2.1.1"
5438-
resolved "https://registry.yarnpkg.com/flux-standard-action/-/flux-standard-action-2.1.1.tgz#b2e204145ea8e4294d6b0f178d8e8c416802948f"
5439-
integrity sha512-W86GzmXmIiTVq/dpYVd2HtTIUX9c35Iq3ao3xR6qcKtuXgbu+BDEj72op5VnEIe/kpuSbhl+I8kT1iS2hpcusw==
5440-
dependencies:
5441-
lodash "^4.17.15"
5442-
54435455
follow-redirects@^1.0.0:
54445456
version "1.13.0"
54455457
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
@@ -6413,7 +6425,7 @@ import-local@^3.0.2:
64136425
pkg-dir "^4.2.0"
64146426
resolve-cwd "^3.0.0"
64156427

6416-
imurmurhash@*, imurmurhash@^0.1.4:
6428+
imurmurhash@^0.1.4:
64176429
version "0.1.4"
64186430
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
64196431
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
@@ -7912,11 +7924,6 @@ lockfile@^1.0.4:
79127924
dependencies:
79137925
signal-exit "^3.0.2"
79147926

7915-
lodash._baseindexof@*:
7916-
version "3.1.0"
7917-
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
7918-
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=
7919-
79207927
lodash._baseuniq@~4.6.0:
79217928
version "4.6.0"
79227929
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
@@ -7925,33 +7932,11 @@ lodash._baseuniq@~4.6.0:
79257932
lodash._createset "~4.0.0"
79267933
lodash._root "~3.0.0"
79277934

7928-
lodash._bindcallback@*:
7929-
version "3.0.1"
7930-
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
7931-
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=
7932-
7933-
lodash._cacheindexof@*:
7934-
version "3.0.2"
7935-
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
7936-
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=
7937-
7938-
lodash._createcache@*:
7939-
version "3.1.2"
7940-
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
7941-
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
7942-
dependencies:
7943-
lodash._getnative "^3.0.0"
7944-
79457935
lodash._createset@~4.0.0:
79467936
version "4.0.3"
79477937
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
79487938
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=
79497939

7950-
lodash._getnative@*, lodash._getnative@^3.0.0:
7951-
version "3.9.1"
7952-
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
7953-
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=
7954-
79557940
lodash._root@~3.0.0:
79567941
version "3.0.1"
79577942
resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692"
@@ -8017,11 +8002,6 @@ lodash.merge@^4.6.1:
80178002
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
80188003
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
80198004

8020-
lodash.restparam@*:
8021-
version "3.6.1"
8022-
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
8023-
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=
8024-
80258005
lodash.sortby@^4.7.0:
80268006
version "4.7.0"
80278007
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"

0 commit comments

Comments
 (0)