Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 656x 656x 656x 656x 656x 656x 656x 656x 656x 656x 98x 81x 81x 98x 656x 656x 656x 656x 656x 656x 656x 1093x 656x 656x 656x 656x 656x 656x 656x 656x 656x 656x 656x 656x 656x 656x 656x 656x 771x 656x 656x 656x 656x 656x 656x 656x 656x 656x 656x 656x 62x | /*!
* Error handling composable for Vue 3 Composition API.
* Provides functions to handle component errors
*
* @module ext.wikilambda.app.composables.useError
* @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
* @license MIT
*/
'use strict';
const { computed } = require( 'vue' );
const { storeToRefs } = require( 'pinia' );
const Constants = require( '../Constants.js' );
const useMainStore = require( '../store/index.js' );
/**
* Error handling composable
*
* @param {Object} options - Options object
* @param {Object} options.keyPath - The keyPath ref from the component
* @return {Object} Error composable API
*/
module.exports = function useError( { keyPath } = {} ) {
const mainStore = useMainStore();
const { clearErrors } = mainStore;
const { getChildErrorKeys, getErrors, getErrorPaths } = storeToRefs( mainStore );
/**
* If keyPath is associated to a field (is defined and
* not at the root level), clear the errors associated to this
* component.
*/
function clearFieldErrors() {
if ( keyPath && keyPath !== Constants.STORED_OBJECTS.MAIN ) {
clearErrors( keyPath );
}
}
/**
* Returns the errors of the component keyPath.
*
* @return {Array}
*/
const fieldErrors = computed( () => keyPath && keyPath !== Constants.STORED_OBJECTS.MAIN ?
getErrors.value( keyPath ) :
[] );
/**
* Returns whether the component is in an error state.
*
* @return {boolean}
*/
const hasFieldErrors = computed( () => fieldErrors.value.length > 0 );
/**
* Returns whether there are any errors stored
* for any child fields of this field.
*
* @return {boolean}
*/
const hasChildErrors = computed( () => keyPath ?
getChildErrorKeys.value( keyPath ).length > 0 :
false );
return {
getChildErrorKeys,
getErrors,
getErrorPaths,
clearFieldErrors,
fieldErrors,
hasFieldErrors,
hasChildErrors
};
};
|