This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// recreation of a computed property | |
const computed = (vm, func) => { | |
vm.$watch( | |
func, | |
null, // callback not used for lazy | |
{ lazy: true }, // lazy means we can just flag as dirty | |
); | |
// eslint-disable-next-line no-underscore-dangle | |
const watcher = vm._watchers[vm._watchers.length - 1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mutations: { | |
setName(state, name) { | |
state.name = name; | |
}, | |
}, | |
actions: { | |
setName({ commit }, name) { | |
commit('setName', name); | |
}, | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actions: { | |
loadBooks({ commit }) { | |
commit('startLoading'); | |
get('/api/books').then((response) => { | |
commit('setBooks', response.data.books); | |
commit('stopLoading'); | |
}); | |
}, | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actions: { | |
async loadBooks({ commit }) { | |
commit('startLoading'); | |
const response = await get('/api/books'); | |
commit('setBooks', response.data.books); | |
commit('stopLoading'); | |
}, | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actions: { | |
loadBooks({ commit }) { | |
commit('startLoading'); | |
return get('/api/books').then((response) => { | |
commit('setBooks', response.data.books); | |
commit('stopLoading'); | |
}); | |
}, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AsyncFunction = (async () => {}).constructor; | |
console.log((() => {}) instanceof AsyncFunction); // false | |
console.log((async () => {}) instanceof AsyncFunction); // true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mutactions: { | |
async loadBooks({ state }) { | |
state.loading += 1; | |
const response = await get('/api/books'); | |
state.books = response.data.books; | |
state.loading -= 1; | |
}, | |
} |