All files / ext.wikilambda.app/store/stores programmingLanguages.js

100% Statements 68/68
100% Branches 5/5
100% Functions 4/4
100% Lines 68/68

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 69103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 21x 21x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 2x 2x 2x 2x 2x 2x 2x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 103x 103x  
/*!
 * WikiLambda Vue editor: Pinia store for programming language-related state, actions, mutations and getters
 *
 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
 * @license MIT
 */
'use strict';
 
const Constants = require( '../../Constants.js' );
 
module.exports = {
	state: {
		/**
		 * Collection of ZProgrammingLanguages
		 */
		allZProgrammingLangs: []
	},
 
	getters: {
		/**
		 * Get all programming languages
		 *
		 * @param {Object} state
		 * @return {Array} List of programming languages
		 */
		getAllProgrammingLangs: function ( state ) {
			return state.allZProgrammingLangs;
		}
	},
 
	actions: {
		/**
		 * Call the mediawiki api to get and store the list of Z61/Programming Languages in the state.
		 * TODO (T296815) - implement API call to backend to get list of Z61.
		 *
		 * @return {Array} List of programming languages.
		 */
		fetchAllZProgrammingLanguages: function () {
			// TODO (T296815): Stop using this hard-coded list and fetch them from the API
			const zProgrammingLanguages = [
				this.createProgrammingLanguage( 'Z600', 'javascript', 'JavaScript' ),
				this.createProgrammingLanguage( 'Z610', 'python', 'Python' )
			];
			this.allZProgrammingLangs = zProgrammingLanguages;
			return zProgrammingLanguages;
		},
 
		/**
		 * Utility function to create a programming language object.
		 *
		 * @param {string} zid ZID of the programming language.
		 * @param {string} code Programming language code.
		 * @param {string} name Programming language name.
		 * @return {Object} Programming language object.
		 */
		createProgrammingLanguage: function ( zid, code, name ) {
			return {
				Z1K1: Constants.Z_PERSISTENTOBJECT,
				Z2K1: { Z1K1: 'Z6', Z6K1: zid },
				Z2K2: {
					Z1K1: Constants.Z_PROGRAMMING_LANGUAGE,
					Z61K1: code,
					Z61K2: name
				}
			};
		}
	}
};