From 85afaabaa9d75106c1db2b9c34753a9891ec12c5 Mon Sep 17 00:00:00 2001 From: Harold Treen Date: Sun, 31 Dec 2017 03:12:35 -0500 Subject: [PATCH] perf(statusTile): faster array creation and lodash lazy loading Remove need for ES6 array polyfills and only import lodash once required re #330 --- .all-contributorsrc | 10 ++++++++++ README.md | 3 ++- src/atomInterface/index.js | 17 +++++++++-------- src/editorInterface/index.js | 19 ++++++++++++++----- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6c0ccb28..102ddf93 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -246,6 +246,16 @@ "contributions": [ "code" ] + }, + { + "login": "haroldtreen", + "name": "Harold Treen", + "avatar_url": "https://avatars2.githubusercontent.com/u/1745854?v=4", + "profile": "https://haroldtreen.com", + "contributions": [ + "bug", + "code" + ] } ] } diff --git a/README.md b/README.md index a989f3ea..7fd73a73 100644 --- a/README.md +++ b/README.md @@ -61,11 +61,12 @@ This repository was created by [James Long][james-long] to go along with his Pre Thanks goes to these people ([emoji key][emojis]): + | [
James Long](http://jlongster.com)
[πŸ’¬](#question-jlongster "Answering Questions") [πŸ’»](https://github.com/prettier/prettier-atom/commits?author=jlongster "Code") [πŸ“–](https://github.com/prettier/prettier-atom/commits?author=jlongster "Documentation") [πŸ”Œ](#plugin-jlongster "Plugin/utility libraries") [πŸ‘€](#review-jlongster "Reviewed Pull Requests") | [
Rob Wise](https://robwise.github.io)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=robwise "Code") [πŸ“–](https://github.com/prettier/prettier-atom/commits?author=robwise "Documentation") [πŸ’¬](#question-robwise "Answering Questions") [πŸ’‘](#example-robwise "Examples") [πŸ‘€](#review-robwise "Reviewed Pull Requests") [⚠️](https://github.com/prettier/prettier-atom/commits?author=robwise "Tests") | [
Kent C. Dodds](https://kentcdodds.com)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=kentcdodds "Code") [πŸ“–](https://github.com/prettier/prettier-atom/commits?author=kentcdodds "Documentation") [πŸš‡](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") | [
Luca Barone](https://github.com/cloud-walker)
| [
Arnar Þór Sveinsson](https://github.com/arnarthor)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=arnarthor "Code") | [
Adam Miskiewicz](http://www.adammiskiewicz.com/)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=skevy "Code") | [
Ori Livni](http://www.orilivni.com)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=oriSomething "Code") | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | [
Leon Chen](https://transcranial.github.io)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=transcranial "Code") | [
Christopher Chedeau](http://blog.vjeux.com/)
[πŸ’¬](#question-vjeux "Answering Questions") [πŸ’»](https://github.com/prettier/prettier-atom/commits?author=vjeux "Code") [πŸ”Œ](#plugin-vjeux "Plugin/utility libraries") | [
Christoph Geschwind](http://christoph-geschwind.de)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=1st8 "Code") | [
Andrew Hutchings](https://andrewhutchings.com)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=ahutchings "Code") | [
David Schnurr](http://davidschnurr.com)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=schnerd "Code") | [
Ryan Cole](http://rycole.com/)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=ryancole "Code") | [
Dara Hak](https://github.com/darahak)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=darahak "Code") [πŸ“–](https://github.com/prettier/prettier-atom/commits?author=darahak "Documentation") | | [
Stephen John Sorensen](http://www.stephenjohnsorensen.com/)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=spudly "Code") | [
Lukas Geiger](https://github.com/lgeiger)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=lgeiger "Code") [⚠️](https://github.com/prettier/prettier-atom/commits?author=lgeiger "Tests") | [
Viktor Charypar](https://github.com/charypar)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=charypar "Code") [⚠️](https://github.com/prettier/prettier-atom/commits?author=charypar "Tests") | [
Mats HΓΆgberg](http://mats.hgbrg.se)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=mhgbrg "Code") | [
Roman](https://github.com/RoM4iK)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=RoM4iK "Code") | [
vaibhav](https://vaibhavchatarkar.com)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=da-vaibhav "Code") | [
Karl Horky](https://work.karlhorky.com)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=karlhorky "Code") | -| [
Dan Abramov](http://twitter.com/dan_abramov)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=gaearon "Code") | [
Murphy Randle](https://sploding.rocks)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=splodingsocks "Code") [πŸ›](https://github.com/prettier/prettier-atom/issues?q=author%3Asplodingsocks "Bug reports") | [
Matthieu Lemoine](https://matthieulemoine.com)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=MatthieuLemoine "Code") | [
Ron Green](https://github.com/rgreenjr)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=rgreenjr "Code") | +| [
Dan Abramov](http://twitter.com/dan_abramov)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=gaearon "Code") | [
Murphy Randle](https://sploding.rocks)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=splodingsocks "Code") [πŸ›](https://github.com/prettier/prettier-atom/issues?q=author%3Asplodingsocks "Bug reports") | [
Matthieu Lemoine](https://matthieulemoine.com)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=MatthieuLemoine "Code") | [
Ron Green](https://github.com/rgreenjr)
[πŸ’»](https://github.com/prettier/prettier-atom/commits?author=rgreenjr "Code") | [
Harold Treen](https://haroldtreen.com)
[πŸ›](https://github.com/prettier/prettier-atom/issues?q=author%3Aharoldtreen "Bug reports") [πŸ’»](https://github.com/prettier/prettier-atom/commits?author=haroldtreen "Code") | This project follows the [all-contributors][all-contributors] specification. Contributions of any kind are welcome! diff --git a/src/atomInterface/index.js b/src/atomInterface/index.js index b5cb3e44..53cc7015 100644 --- a/src/atomInterface/index.js +++ b/src/atomInterface/index.js @@ -44,14 +44,15 @@ const getGraphQlScopes = () => getConfigOption('formatOnSaveOptions.graphQlScope const getMarkdownScopes = () => getConfigOption('formatOnSaveOptions.markdownScopes'); -const getAllScopes = () => [ - ...getJavascriptScopes(), - ...getTypescriptScopes(), - ...getCssScopes(), - ...getJsonScopes(), - ...getGraphQlScopes(), - ...getMarkdownScopes(), -]; +const getAllScopes = () => + [ + getJavascriptScopes(), + getTypescriptScopes(), + getCssScopes(), + getJsonScopes(), + getGraphQlScopes(), + getMarkdownScopes(), + ].reduce((acc, els) => acc.concat(els)); const getWhitelistedGlobs = () => getConfigOption('formatOnSaveOptions.whitelistedGlobs'); diff --git a/src/editorInterface/index.js b/src/editorInterface/index.js index acddd5a3..cbe37d3d 100644 --- a/src/editorInterface/index.js +++ b/src/editorInterface/index.js @@ -1,5 +1,5 @@ // @flow -const _ = require('lodash/fp'); + const path = require('path'); const { @@ -10,6 +10,14 @@ const { getMarkdownScopes, } = require('../atomInterface'); +let flow; +const lazyFlow = () => { + if (!flow) { + flow = require('lodash/fp/flow'); // eslint-disable-line global-require + } + return flow; +}; + const EMBEDDED_SCOPES = ['text.html.vue', 'text.html.basic']; const getBufferRange = (editor: TextEditor) => editor.getBuffer().getRange(); @@ -33,10 +41,11 @@ const isCurrentScopeMarkdownScope = (editor: TextEditor) => const getCurrentFilePath = (editor: TextEditor) => (editor.buffer.file ? editor.buffer.file.path : undefined); -const getCurrentDir: (editor: TextEditor) => ?string = _.flow( - getCurrentFilePath, - (maybeFilePath: ?string) => (typeof maybeFilePath === 'string' ? path.dirname(maybeFilePath) : undefined), -); +const getCurrentDir: (editor: TextEditor) => ?string = editor => + lazyFlow()( + getCurrentFilePath, + (maybeFilePath: ?string) => (typeof maybeFilePath === 'string' ? path.dirname(maybeFilePath) : undefined), + )(editor); module.exports = { getBufferRange,