All files / ext.wikilambda.edit/store/modules programmingLanguages.js

57.14% Statements 4/7
100% Branches 0/0
66.66% Functions 2/3
57.14% Lines 4/7

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              2x   2x                             2x                     1x                                                                                              
/*!
 * WikiLambda Vue editor: Store module for programming language-related state, actions, mutations and getters
 *
 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
 * @license MIT
 */
 
var Constants = require( '../../Constants.js' );
 
module.exports = exports = {
	state: {
		/**
		 * Collection of ZProgrammingLanguages
		 */
		allZProgrammingLangs: []
	},
	getters: {
		/**
		 * Get all programming languages
		 *
		 * @param {Object} state
		 * @return {Array} allZProgrammingLangs
		 */
		getAllProgrammingLangs: function ( state ) {
			return state.allZProgrammingLangs;
		}
	},
	mutations: {
		/**
		 * setAllZProgrammingLangs
		 *
		 * @param {Object} state
		 * @param {Object} allLangs
		 */
		setAllZProgrammingLangs: function ( state, allLangs ) {
			state.allZProgrammingLangs = allLangs;
		}
	},
	actions: {
		/**
		 * Call the mediawiki api to get and store the list of Z61/Programming Languages in the state.
		 * TODO - implement API call to backend to get list of Z61.
		 *
		 * @param {Object} context
		 * @return {Object}
		 */
		fetchAllZProgrammingLanguages: function ( context ) {
			// TODO(T296815): Stop using this hard-coded list and fetch them from the API
			var zProgrammingLanguages = [
				{
					Z1K1: Constants.Z_PERSISTENTOBJECT,
					Z2K1: 'Z600',
					Z2K2: {
						Z1K1: Constants.Z_PROGRAMMING_LANGUAGE,
						Z61K1: 'javascript',
						Z61K2: 'JavaScript'
					}
				},
				{
					Z1K1: Constants.Z_PERSISTENTOBJECT,
					Z2K1: 'Z610',
					Z2K2: {
						Z1K1: Constants.Z_PROGRAMMING_LANGUAGE,
						Z61K1: 'python',
						Z61K2: 'Python'
					}
				},
				{
					Z1K1: Constants.Z_PERSISTENTOBJECT,
					Z2K1: 'Z620',
					Z2K2: {
						Z1K1: Constants.Z_PROGRAMMING_LANGUAGE,
						Z61K1: 'lua',
						Z61K2: 'Lua'
					}
				}
			];
			context.commit( 'setAllZProgrammingLangs', zProgrammingLanguages );
			return zProgrammingLanguages;
		}
	}
};