Complete Vue.js 2 Web Development_ Practical guide to building end-to-end web development solutions with Vue.js 2

(singke) #1

Pre-Caching Other Folders and Files for Faster Navigation Chapter 7


path() {
return this.$store.state.path
}
},
methods: {

/**
* Dropbox API instance
* @return {object}
*/
dropbox() {
return new Dropbox({
accessToken: this.accessToken
});
},

/**
* @param {string} path The path to a folder
* @return {string} A cache-friendly URL without punctuation/symbals
*/
generateSlug(path) {
return path.toLowerCase()
.replace(/^\/|\/$/g, '')
.replace(/ /g,'-')
.replace(/\//g,'-')
.replace(/[-]+/g, '-')
.replace(/[^\w-]+/g,'');
},

/**
* Retrieve the folder structure form the cache or Dropbox API
* @param {string} path The folder path
* @return {Promise} A promise containing the folder data
*/
getFolderStructure(path) {
let output;

const slug = this.generateSlug(path),
data = this.$store.state.structure[slug];
if(data) {
output = Promise.resolve(data);
} else {
output = this.dropbox().filesListFolder({
path: path,
include_media_info: true
})
.then(response => {
let entries = response.entries;
Free download pdf