Skip to content

Commit

Permalink
Get rid of lodash.isequal
Browse files Browse the repository at this point in the history
  • Loading branch information
zewish committed Sep 8, 2022
1 parent fa7935e commit 249574a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 62 deletions.
101 changes: 57 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "redux-remember",
"version": "3.1.0",
"version": "3.1.1",
"description": "Saves and loads your redux state from a key-value store of your choice",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down Expand Up @@ -54,7 +54,7 @@
"react-native"
],
"dependencies": {
"lodash.isequal": "^4.5.0"
"lauqe": "^1.5.0"
},
"devDependencies": {
"@babel/cli": "^7.12.16",
Expand All @@ -65,7 +65,6 @@
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.1.1",
"@types/jest": "^26.0.20",
"@types/lodash.isequal": "^4.5.6",
"@wessberg/rollup-plugin-ts": "^1.3.8",
"babel-jest": "^26.6.3",
"cross-env": "^7.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/init.test.ts
Expand Up @@ -131,7 +131,7 @@ describe('init.ts', () => {

it('does not call store.dispatch()', async () => {
jest.resetModules();
jest.mock('lodash.isequal', () => () => true);
jest.mock('lauqe', () => ({ equal: () => true }));

await require('../init').default(...args);
expect(mockStore.dispatch).toBeCalledTimes(0);
Expand Down
17 changes: 8 additions & 9 deletions src/__tests__/persist.test.ts
Expand Up @@ -14,10 +14,9 @@ describe('persist.ts', () => {

mockIsEqual = jest.fn((a, b) => a === b);

jest.mock(
'lodash.isequal',
() => mockIsEqual
);
jest.mock('lauqe', () => ({
equal: mockIsEqual
}));

mod = require('../persist');
});
Expand All @@ -28,7 +27,7 @@ describe('persist.ts', () => {
});

describe('saveAllKeyed()', () => {
it('calls lodash.isequal()', async () => {
it('calls lauqe.equal()', async () => {
await mod.saveAllKeyed(
{
key1: 'val1',
Expand Down Expand Up @@ -113,7 +112,7 @@ describe('persist.ts', () => {
});

it('does not call driver.setItem()', async () => {
jest.mock('lodash.isequal', () => () => true);
jest.mock('lauqe', () => ({ equal: () => true }));
jest.resetModules();

mod = require('../persist');
Expand All @@ -139,7 +138,7 @@ describe('persist.ts', () => {
});

describe('saveAll()', () => {
it('calls lodash.isequal()', async () => {
it('calls lauqe.equal()', async () => {
const state = {
key1: 'val1',
key2: 'val2'
Expand Down Expand Up @@ -222,7 +221,7 @@ describe('persist.ts', () => {
});

it('does not call driver.setItem()', async () => {
jest.mock('lodash.isequal', () => () => true);
jest.mock('lauqe', () => ({ equal: () => true }));
jest.resetModules();

mod = require('../persist');
Expand Down Expand Up @@ -291,7 +290,7 @@ describe('persist.ts', () => {
});

it('calls console.warn()', async () => {
jest.mock('lodash.isequal', () => () => false);
jest.mock('lauqe', () => ({ equal: () => false }));
jest.resetModules();

mod = require('../persist');
Expand Down
4 changes: 2 additions & 2 deletions src/init.ts
Expand Up @@ -2,7 +2,7 @@ import { Store } from 'redux';
import { ExtendedOptions } from './types';
import { rehydrate } from './rehydrate';
import { persist } from './persist';
import isEqual from 'lodash.isequal';
import { equal } from 'lauqe';
import { REMEMBER_PERSISTED } from './action-types';
import { pick, throttle } from './utils';

Expand Down Expand Up @@ -38,7 +38,7 @@ const init = async (
{ prefix, driver, serialize, persistWholeStore }
);

if (!isEqual(state, oldState)) {
if (!equal(state, oldState)) {
store.dispatch({
type: REMEMBER_PERSISTED,
payload: state
Expand Down
6 changes: 3 additions & 3 deletions src/persist.ts
@@ -1,4 +1,4 @@
import isEqual from 'lodash.isequal';
import { equal } from 'lauqe';
import { ExtendedOptions } from './types';

type SaveAllOptions = Pick<
Expand All @@ -11,7 +11,7 @@ export const saveAll = (
oldState: any,
{ prefix, driver, serialize }: SaveAllOptions
) => {
if (!isEqual(state, oldState)) {
if (!equal(state, oldState)) {
return driver.setItem(
`${prefix}rootState`,
serialize(state, 'rootState')
Expand All @@ -25,7 +25,7 @@ export const saveAllKeyed = (
{ prefix, driver, serialize }: SaveAllOptions
) => Promise.all(
Object.keys(state).map(key => {
if (isEqual(state[key], oldState[key])) {
if (equal(state[key], oldState[key])) {
return Promise.resolve();
}

Expand Down

0 comments on commit 249574a

Please sign in to comment.