Skip to content

Commit 1527502

Browse files
committed
refactor(array): update
1 parent 08c8c88 commit 1527502

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

src/draft.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const draftsCache = new WeakSet<object>();
3838

3939
let arrayHandling = false;
4040

41+
const proxyArrayMethods = ['splice', 'shift', 'unshift', 'reverse'];
42+
4143
const proxyHandler: ProxyHandler<ProxyDraft> = {
4244
get(target: ProxyDraft, key: string | number | symbol, receiver: any) {
4345
const copy = target.copy?.[key];
@@ -93,7 +95,7 @@ const proxyHandler: ProxyHandler<ProxyDraft> = {
9395
const desc = getDescriptor(source, key);
9496
const value = desc?.value;
9597
if (target.type === DraftType.Array) {
96-
if (['splice', 'shift', 'unshift', 'reverse'].includes(key as string)) {
98+
if (proxyArrayMethods.includes(key as string)) {
9799
return function (this: any, ...args: any[]) {
98100
let returnValue: any;
99101
arrayHandling = true;

test/performance/benchmark-reducer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from 'immer';
1616
import { create } from '../..';
1717

18+
// repo: https://github.com/markerikson/immer-perf-tests
1819
function createInitialState() {
1920
const initialState = {
2021
largeArray: Array.from({ length: 10000 }, (_, i) => ({

test/performance/benchmark-reducer1.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { produce as produce10, setAutoFreeze as setAutoFreeze10 } from 'immer';
22
import { create as produceMutative } from '../../dist/mutative.esm.mjs';
33
import { bench, run, summary } from 'mitata';
44

5+
// repo: https://github.com/markerikson/immer-perf-tests
56
function createInitialState() {
67
const initialState = {
78
largeArray: Array.from({ length: 10000 }, (_, i) => ({

0 commit comments

Comments
 (0)