diff --git a/docs/.vuepress/components/AirportCodes.vue b/docs/.vuepress/components/AirportCodes.vue new file mode 100644 index 0000000..e3a0718 --- /dev/null +++ b/docs/.vuepress/components/AirportCodes.vue @@ -0,0 +1,116 @@ + + + + + diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 2bed2c8..4d6041a 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -122,6 +122,7 @@ module.exports = { ['guide/vuex', 'Vuex'], ['guide/ajax', 'AJAX'], ['guide/loops', 'Using in Loops'], + ['guide/bigdata', 'Large Datasets'], ], }, { diff --git a/docs/.vuepress/enhanceApp.js b/docs/.vuepress/enhanceApp.js index a3fac4d..5755185 100644 --- a/docs/.vuepress/enhanceApp.js +++ b/docs/.vuepress/enhanceApp.js @@ -1,6 +1,9 @@ import vSelect from '../../src/components/Select'; export default ({Vue, options, router, siteData}) => { + // Vue.config.performance = true; + Vue.config.devtools = true; + Vue.component('v-select', vSelect); /** diff --git a/docs/guide/bigdata.md b/docs/guide/bigdata.md new file mode 100644 index 0000000..f26b8bd --- /dev/null +++ b/docs/guide/bigdata.md @@ -0,0 +1,38 @@ +# Working with Big Datasets + +When your `options` array gets into the thousands, you will start to see performance dip. If you +have 2,000 options, you have 2,000 dom nodes being rendered into the dropdown. It's very difficult +to render that many nodes at once and maintain 60fps in the browser. + +Regardless of whether your options are primitives or objects, the performance hit comes from +rendering their text labels (or slot) to the dom. The path to keeping things snappy is then to limit +the amount of nodes that get rendered to the dropdown. + +## Optimized Filtering + +You can optimize performance by tweaking Vue Select's filtering and implementing it yourself. +Consider a list of airport codes with roughly ~7,500 entries. Rendering out 7,500 airports doesn't +actually help the user much, they're just looking for one in particular. + + + +The only difference between these two examples is the `filter` prop. Here's the `filter` for the +optimized example: + +```js +filter (airports, search) { + if (search.length === 0) { + return airports.slice(0, 50); + } + return airports.filter(airport => { + const keys = ['name', 'city', 'country', 'iata', 'icao']; + return keys.some(key => String(airport[key]).toLowerCase().includes(search.toLowerCase())) + }).slice(0, 50); +} +``` + +If there's no search text, we only display the first 50 options. If there is a search query, we'll +check if any keys on the object include the search string. Again, we'll limit this to 50 options. + +The key to have Vue Select perform well with thousands of options is to limit the number of options +that are displayed to the end user, without hindering their ability to select the right option. diff --git a/docs/package.json b/docs/package.json index 1fcd52b..285dae6 100644 --- a/docs/package.json +++ b/docs/package.json @@ -14,6 +14,7 @@ "@vuepress/plugin-pwa": "^1.0.0-alpha.47", "@vuepress/plugin-register-components": "^1.0.0-alpha.47", "@vuepress/plugin-search": "^1.0.0-alpha.47", + "airport-data": "^1.0.1", "cross-env": "^5.2.0", "fuse.js": "^3.4.4", "gh-pages": "^0.11.0", diff --git a/docs/yarn.lock b/docs/yarn.lock index 8548f5b..43a28d3 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -1161,6 +1161,11 @@ agentkeepalive@^2.2.0: resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-2.2.0.tgz#c5d1bd4b129008f1163f236f86e5faea2026e2ef" integrity sha1-xdG9SxKQCPEWPyNvhuX66iAm4u8= +airport-data@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/airport-data/-/airport-data-1.0.1.tgz#41c743c48fc5b37765a1bd3cf0617c1de8151316" + integrity sha1-QcdDxI/Fs3dlob088GF8HegVExY= + ajv-errors@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.1.tgz#f35986aceb91afadec4102fbd85014950cefa64d"