Skip to content

Commit

Permalink
removing array spread
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislavsky34200 committed Sep 10, 2023
1 parent 1b5983e commit 44d312b
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ module.exports = {
{ extensions: ['.tsx'] },
],
'react/react-in-jsx-scope': 'off',
'prefer-rest-params': 'off',
'prefer-spread': 'off',
},
},
{
Expand Down
10 changes: 5 additions & 5 deletions src/providers/debugConsole/debugConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ export const getLoggerFn = (
flags[DEBUG_CONSOLE_FEATURE] && !isCounterSilent(counterOptions)
? bindArg(
bindArgs(
[
ctx,
getCounterKey(counterOptions),
...(params ? [`${message}. Params:`, params] : [message]),
],
[ctx, getCounterKey(counterOptions)].concat(
(params
? [`${message}. Params:`, params]
: [message]) as any[],
),
consoleLog,
),
call,
Expand Down
6 changes: 2 additions & 4 deletions src/providers/firstPartyMethod/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export const initProvider = () => {
),
}));

YM_LOG_WHITELIST_KEYS.push(
FIRST_PARTY_PARAMS_KEY,
FIRST_PARTY_HASHED_PARAMS_KEY,
);
YM_LOG_WHITELIST_KEYS.push(FIRST_PARTY_PARAMS_KEY);
YM_LOG_WHITELIST_KEYS.push(FIRST_PARTY_HASHED_PARAMS_KEY);
}
};
4 changes: 2 additions & 2 deletions src/providers/stackProxy/stackProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
pipe,
curry2,
} from 'src/utils/function';
import { cForEach, cReduce, toArray } from 'src/utils/array';
import { arrayMerge, cForEach, cReduce, toArray } from 'src/utils/array';
import { parseDecimalInt } from 'src/utils/number';
import { DEFAULT_COUNTER_TYPE, RSYA_COUNTER_TYPE } from '../counterOptions';
import { consoleLog } from '../debugConsole/debugConsole';
Expand Down Expand Up @@ -147,7 +147,7 @@ export const handleCall = curry2((ctx: Window, item: StackCall) => {
stackList = [];
counterInfo.stackList = stackList;
}
stackList.push([counterKey, method, ...args]);
stackList.push(arrayMerge([counterKey, method], args));
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/sender/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const getSender: GetSender = ctxErrorLogger(
const senderOpt = mix(rawSenderOpt, {
transportInfo: mix(transportInfo, { debugStack: [provider] }),
} as InternalSenderInfo);
return senderFn(senderOpt, ...rest);
return senderFn.apply(null, [senderOpt].concat(rest) as any);
} as GetSenderType<typeof provider>;
},
/*
Expand Down
9 changes: 3 additions & 6 deletions src/utils/array/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import { bindThisForMethod } from '../function/bind/bind';
import { firstArg } from '../function/identity';
import { cForEach } from './map';

/*
Почему не a.push(...b)? Потому что есть бага
https://bugs.webkit.org/show_bug.cgi?id=80797
/**
@function arrayMerge
@summary Why use this instaead of a.push(...b)? Because of the bug here https://bugs.webkit.org/show_bug.cgi?id=80797
*/

/* TODO Concat is widely supported and thus better suits here.
We can use concat, when it's native and this function as a polyfill */
export const arrayMerge = <A extends any[], B extends any[]>(
source: A,
part: B,
Expand Down
10 changes: 8 additions & 2 deletions src/utils/dom/select.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { toArray, flatMap, cFilter, cIndexOf } from 'src/utils/array';
import {
toArray,
flatMap,
cFilter,
cIndexOf,
arrayMerge,
} from 'src/utils/array';
import { bindArg } from 'src/utils/function';
import { isQuerySelectorSupported } from './queySelect';

Expand Down Expand Up @@ -41,7 +47,7 @@ export const querySelectorByTagNamePolyfill = (
tags: string[],
target: Element | Document,
): Element[] => {
const copiedTags = [...tags];
const copiedTags = arrayMerge([], tags);
const tag = copiedTags.shift();
if (!tag) {
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/function/bind/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const callBind = function bindDecorator(bindFunc: F.Function): Bind {
// eslint-disable-next-line prefer-rest-params
const bindArgs = argsToArray(arguments);
const [fn, ctx, ...args] = bindArgs;
return bindFunc.apply(fn, [ctx, ...args]);
return bindFunc.apply(fn, [ctx].concat(args));
};
};
const callNativeOrPoly = nativeBind ? callBind(nativeBind) : bindPoly;
Expand Down
6 changes: 3 additions & 3 deletions src/utils/function/callUserCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setDeferBase } from 'src/utils/defer/base';
import { AnyFunc, CallUserCallback } from './types';
import { argsToArray } from './args';
import { isFunction, isNil } from '../object/assertions';
import { bindArg, bind } from './bind/bind';
import { bindArg } from './bind/bind';
import { throwFunction } from '../errorLogger/throwFunction';

/**
Expand All @@ -20,9 +20,9 @@ export const callUserCallback: CallUserCallback = function z(
// eslint-disable-next-line prefer-rest-params
const [, , , ...args] = argsToArray(arguments);
if (!isNil(userContext)) {
bind(callback, userContext, ...args)();
callback.apply(userContext, args);
} else {
callback(...args);
callback.apply(null, args);
}
}
} catch (error) {
Expand Down
7 changes: 4 additions & 3 deletions src/utils/function/globalMemo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getVersion } from 'src/version';
import { getGlobalStorage } from 'src/storage/global';
import { getPath } from 'src/utils/object/path';
import { argsToArray } from './args';
import { memo } from './memo';

const MEMO_FN_KEY = `m${getVersion()}`;
Expand Down Expand Up @@ -37,7 +36,7 @@ export const globalMemoWin = <R, T extends Variadic = Variadic>(
): ctxFunction<T, R> => {
return function globalMemoWrapper() {
// eslint-disable-next-line prefer-rest-params
const [ctx, ...args] = argsToArray(arguments);
const ctx = arguments[0];

const storage = getGlobalStorage(ctx);
const gsKey = global ? GLOBAL_MEMO_FN_KEY : MEMO_FN_KEY;
Expand All @@ -50,6 +49,8 @@ export const globalMemoWin = <R, T extends Variadic = Variadic>(
storage.setVal(gsKey, memoStorage);
}

return wrappedFunction(ctx, ...args);
// eslint-disable-next-line prefer-rest-params

This comment has been minimized.

Copy link
@ErDmKo
// eslint-disable-next-line prefer-spread
return wrappedFunction.apply(null, arguments);
};
};
6 changes: 5 additions & 1 deletion src/utils/phones/phonesDom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ctxReduce,
arrayJoin,
filterFalsy,
arrayMerge,
} from 'src/utils/array';
import { waitForBodyTask } from 'src/utils/dom/waitForBody';
import { memo, bindArg } from 'src/utils/function';
Expand Down Expand Up @@ -183,7 +184,10 @@ export const selectLink = (ctx: Window, phoneChangeMap: PhoneChangeMap) => {
: [telFromHref, ''],
]);

accum.push(...selectText(ctx, textsPhoneChangeMap, link));
arrayMerge(
accum,
selectText(ctx, textsPhoneChangeMap, link),
);
}
}

Expand Down

0 comments on commit 44d312b

Please sign in to comment.