Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lodash from core #2827

Merged
merged 10 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 15 additions & 43 deletions js/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 js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
"expose-loader": "^1.0.3",
"jquery": "^3.6.0",
"jquery.hotkeys": "^0.1.0",
"lodash-es": "^4.17.21",
"mithril": "^2.0.4",
"punycode": "^2.1.1",
"spin.js": "^3.1.0",
"textarea-caret": "^3.1.0"
"textarea-caret": "^3.1.0",
"throttle-debounce": "^3.0.1"
},
"devDependencies": {
"@babel/preset-typescript": "^7.13.0",
"@types/jquery": "^3.5.5",
"@types/lodash-es": "^4.17.4",
"@types/mithril": "^2.0.7",
"@types/punycode": "^2.1.0",
"@types/textarea-caret": "^3.0.0",
Expand Down
3 changes: 1 addition & 2 deletions js/src/common/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Discussion from './models/Discussion';
import Post from './models/Post';
import Group from './models/Group';
import Notification from './models/Notification';
import { flattenDeep } from 'lodash-es';
import PageState from './states/PageState';
import ModalManagerState from './states/ModalManagerState';
import AlertManagerState from './states/AlertManagerState';
Expand Down Expand Up @@ -184,7 +183,7 @@ export default class Application {
Object.keys(extensions).forEach((name) => {
const extension = extensions[name];

const extenders = flattenDeep(extension.extend);
const extenders = extension.extend.flat(Infinity);

for (const extender of extenders) {
extender.extend(this, { name, exports: extension });
Expand Down
2 changes: 2 additions & 0 deletions js/src/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ patchMithril(window);
import * as Extend from './extend/index';

export { Extend };

import './utils/arrayFlatPolyfill';
25 changes: 25 additions & 0 deletions js/src/common/utils/arrayFlatPolyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Based off of the CC-0 polyfill at https://github.com/jonathantneal/array-flat-polyfill
//
// Needed to provide support for Safari on iOS < 12

if (!Array.prototype['flat']) {
Array.prototype['flat'] = function flat(depth?: number) {
const realDepth = isNaN(depth as any) ? 1 : depth;

return realDepth
? Array.prototype.reduce.call(
this,
function (acc, cur) {
if (Array.isArray(cur)) {
acc.push.apply(acc, flat.call(cur, realDepth - 1));
} else {
acc.push(cur);
}

return acc;
},
[]
)
: Array.prototype.slice.call(this);
};
}
10 changes: 10 additions & 0 deletions js/src/common/utils/escapeRegExp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const specialChars = /[.*+?^${}()|[\]\\]/g;

/**
* Escapes the `RegExp` special characters in `input`.
*
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
*/
export default function escapeRegExp(input: string): string {
return input.replace(specialChars, '\\$&');
}
2 changes: 1 addition & 1 deletion js/src/forum/components/DiscussionListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import slidable from '../utils/slidable';
import extractText from '../../common/utils/extractText';
import classList from '../../common/utils/classList';
import DiscussionPage from './DiscussionPage';
import escapeRegExp from '../../common/utils/escapeRegExp';

import { escapeRegExp } from 'lodash-es';
/**
* The `DiscussionListItem` component shows a single discussion in the
* discussion list.
Expand Down
6 changes: 3 additions & 3 deletions js/src/forum/states/PostStreamState.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { throttle } from 'lodash-es';
import { throttle } from 'throttle-debounce';
import anchorScroll from '../../common/utils/anchorScroll';

class PostStreamState {
Expand Down Expand Up @@ -50,8 +50,8 @@ class PostStreamState {
*/
this.forceUpdateScrubber = false;

this.loadNext = throttle(this._loadNext, 300);
this.loadPrevious = throttle(this._loadPrevious, 300);
this.loadNext = throttle(300, this._loadNext);
this.loadPrevious = throttle(300, this._loadPrevious);

this.show(includedPosts);
}
Expand Down