All files / ext.wikilambda.edit/components/function ZFunctionEvaluator.vue

100% Statements 19/19
100% Branches 3/3
100% Functions 5/5
100% Lines 19/19

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 76 77 78 79 80 81 82 83 84                              19x 19x 19x 19x     19x           6x                                 6x   6x   6x     6x     6x   6x         6x   4x 4x     2x 2x 2x       6x                    
<template>
	<!--
		WikiLambda Vue component for evaluation of ZFunction objects.
 
		@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
		@license MIT
	-->
	<div v-if="resultId">
		<wl-z-function-call-runner
			:zobject-id="functionCallId"
		></wl-z-function-call-runner>
	</div>
</template>
 
<script>
var Constants = require( '../../Constants.js' ),
	ZFunctionCallRunner = require( './ZFunctionCallRunner.vue' ),
	mapActions = require( 'vuex' ).mapActions,
	mapGetters = require( 'vuex' ).mapGetters;
 
// @vue/component
module.exports = exports = {
	name: 'wl-z-function-evaluator',
	components: {
		'wl-z-function-call-runner': ZFunctionCallRunner
	},
	data: function () {
		return {
			functionCallId: '',
			resultId: ''
		};
	},
	computed: mapGetters( {
		getNestedZObjectById: 'getNestedZObjectById',
		getCurrentZObjectId: 'getCurrentZObjectId',
		getCurrentZObjectType: 'getCurrentZObjectType',
		getZObjectAsJson: 'getZObjectAsJson'
	} ),
	methods: mapActions( [
		'initializeResultId',
		'addZFunctionCall',
		'injectZObject'
	] ),
	mounted: function () {
		this.initializeResultId( this.functionCallId )
			.then( function ( id ) {
				this.functionCallId = id;
 
				return this.addZFunctionCall( { id: this.functionCallId } );
			}.bind( this ) )
			.then( function () {
				return this.initializeResultId( this.resultId );
			}.bind( this ) )
			.then( function ( id ) {
				this.resultId = id;
 
				var zFunctionCall = this.getNestedZObjectById( this.functionCallId, [
					Constants.Z_FUNCTION_CALL_FUNCTION
				] );
				var zFunctionId;
 
				switch ( this.getCurrentZObjectType ) {
					case Constants.Z_FUNCTION:
						zFunctionId = this.getCurrentZObjectId;
						break;
					case Constants.Z_IMPLEMENTATION:
						// eslint-disable-next-line max-len
						var zImplementationFunction = this.getZObjectAsJson[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_IMPLEMENTATION_FUNCTION ];
						if ( zImplementationFunction ) {
							zFunctionId = zImplementationFunction[ Constants.Z_REFERENCE_ID ];
						}
				}
 
				return this.injectZObject( {
					zobject: zFunctionId,
					key: Constants.Z_FUNCTION_CALL_FUNCTION,
					id: zFunctionCall.id,
					parent: this.functionCallId
				} );
			}.bind( this ) );
	}
};
</script>