🔥 Deletes ExampleWidget, adds tutorial for creating widget

This commit is contained in:
Alicia Sykes
2021-12-14 20:31:00 +00:00
parent 3da76ce299
commit 66067b002f
6 changed files with 214 additions and 153 deletions

View File

@@ -1,6 +1,6 @@
/**
* Mixin that all pre-built and custom widgets extend from.
* Manages loading state, error handling and data updates.
* Manages loading state, error handling, data updates and user options
*/
import ProgressBar from 'rsup-progress';
import ErrorHandler from '@/utils/ErrorHandler';
@@ -15,10 +15,15 @@ const WidgetMixin = {
data: () => ({
progress: new ProgressBar({ color: 'var(--progress-bar)' }),
}),
/* When component mounted, fetch initial data */
mounted() {
this.fetchData();
},
methods: {
/* Re-fetches external data, called by parent. Usually overridden by widget */
update() {
console.log('No update method configured for this widget'); // eslint-disable-line no-console
this.startLoading();
this.fetchData();
},
/* Called when an error occurs. Logs to handler, and passes to parent component */
error(msg, stackTrace) {
@@ -35,6 +40,10 @@ const WidgetMixin = {
this.$emit('loading', false);
setTimeout(() => { this.progress.end(); }, 500);
},
/* Overridden by child component. Will make network request, then end loader */
fetchData() {
this.finishLoading();
},
},
};