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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | 13x 132x 132x 132x 302x 170x 170x 170x 132x 128x 128x 128x 343x 215x 559x 344x 344x 49x 132x 132x 132x 249x 117x 117x 1x 13x 11x 943x 223x 88x 88x 77x 77x 26x 88x 50x 17x 12x 5x 5x 5x 5x 5x 5x 5x 4x 5x 16x 11x 5x 5x 11x 11x 11x 11x 143x 143x 11x 132x 132x 132x 132x 220x 19x | /*! * WikiLambda Vuex code to manipulate the current ZObject. * * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt * @license MIT */ var Constants = require( '../../../Constants.js' ); /** * Adds languages found in the zObject name labels to the given langsList. * * @param {Object} getters * @param {Array} langsList */ function addLanguagesFromNameLabels( getters, langsList ) { var zObjectLabels = getters.getZObjectAsJson[ Constants.Z_PERSISTENTOBJECT_LABEL ]; // Don't break if the labels are set to {} if ( zObjectLabels[ Constants.Z_MULTILINGUALSTRING_VALUE ] ) { zObjectLabels[ Constants.Z_MULTILINGUALSTRING_VALUE ].forEach( function ( label ) { if ( label[ Constants.Z_MONOLINGUALSTRING_LANGUAGE ] ) { var lang = label[ Constants.Z_MONOLINGUALSTRING_LANGUAGE ][ Constants.Z_REFERENCE_ID ]; if ( langsList.indexOf( lang ) === -1 ) { langsList.push( label[ Constants.Z_MONOLINGUALSTRING_LANGUAGE ][ Constants.Z_REFERENCE_ID ] ); } } } ); } } /** * Adds languages found in the zObject argument labels to the given langsList. * * @param {Object} getters * @param {Array} langsList */ function addLanguagesFromArgumentLabels( getters, langsList ) { if ( getters.getZObjectAsJson[ Constants.Z_PERSISTENTOBJECT_VALUE ] ) { var zArguments = getters.getZObjectAsJson[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_FUNCTION_ARGUMENTS ]; if ( zArguments ) { zArguments.forEach( function ( arg ) { // Don't break if the labels are set to {} if ( arg[ Constants.Z_ARGUMENT_LABEL ] && arg[ Constants.Z_ARGUMENT_LABEL ][ Constants.Z_MULTILINGUALSTRING_VALUE ] ) { arg[ Constants.Z_ARGUMENT_LABEL ][ Constants.Z_MULTILINGUALSTRING_VALUE ].forEach( function ( label ) { if ( label[ Constants.Z_MONOLINGUALSTRING_LANGUAGE ] ) { var lang = label[ Constants.Z_MONOLINGUALSTRING_LANGUAGE ][ Constants.Z_REFERENCE_ID ]; if ( langsList.indexOf( lang ) === -1 ) { langsList.push( label[ Constants.Z_MONOLINGUALSTRING_LANGUAGE ][ Constants.Z_REFERENCE_ID ] ); } } } ); } } ); } } } /** * Adds languages found in the zObject alias name labels to the given langsList. * * @param {Object} getters * @param {Array} langsList */ function addLanguagesFromAliasLabels( getters, langsList ) { var zAliases = getters.getZObjectAsJson[ Constants.Z_PERSISTENTOBJECT_ALIASES ]; // Don't break if the labels are set to {} if ( zAliases[ Constants.Z_MULTILINGUALSTRINGSET_VALUE ] ) { zAliases[ Constants.Z_MULTILINGUALSTRINGSET_VALUE ].forEach( function ( alias ) { if ( alias[ Constants.Z_MONOLINGUALSTRINGSET_LANGUAGE ] ) { var lang = alias[ Constants.Z_MONOLINGUALSTRINGSET_LANGUAGE ][ Constants.Z_REFERENCE_ID ]; if ( langsList.indexOf( lang ) === -1 ) { langsList.push( alias[ Constants.Z_MONOLINGUALSTRINGSET_LANGUAGE ][ Constants.Z_REFERENCE_ID ] ); } } } ); } } module.exports = exports = { state: { currentZid: Constants.NEW_ZID_PLACEHOLDER }, mutations: { /** * Set the value of the current Zid * * @param {Object} state * @param {string} currentZid */ setCurrentZid: function ( state, currentZid ) { state.currentZid = currentZid; } }, getters: { /** * Return the complete zObject as a JSON * * @param {Object} state * @param {Object} getters * @param {Object} rootState * @param {Object} rootGetters * @return {Array} zObjectJson */ getZObjectAsJson: function ( state, getters, rootState, rootGetters ) { return rootGetters.getZObjectAsJsonById( 0, rootState.zobjectModule.zobject[ 0 ].value === 'array' ); }, /** * Return the root ZObjectId, equivalend to the Z_REFERENCE_ID of Z_PERSISTENTOBJECT_ID * * @param {Object} state * @return {string} currentZObjectId */ getCurrentZObjectId: function ( state ) { return state.currentZid || Constants.NEW_ZID_PLACEHOLDER; }, /** * Return the root ZObjectId type * * @param {Object} state * @param {Object} getters * @return {string} currentZObjectTypeId */ getCurrentZObjectType: function ( state, getters ) { var zobject = getters.getZObjectAsJson, type; if ( zobject && zobject[ Constants.Z_PERSISTENTOBJECT_VALUE ] ) { type = zobject[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_OBJECT_TYPE ]; if ( typeof type === 'object' ) { type = type[ Constants.Z_REFERENCE_ID ]; } } return type || false; }, /** * Return a boolean value indicating if the current zObject is executable. * * @param {Object} state * @param {Object} getters * @return {boolean} */ isCurrentZObjectExecutable: function ( state, getters ) { return [ Constants.Z_FUNCTION, Constants.Z_IMPLEMENTATION ].indexOf( getters.getCurrentZObjectType ) !== -1; }, // TODO: use this check for ZFunction warnings currentZFunctionHasValidInputs: function ( state, getters ) { if ( getters.getCurrentZObjectType !== Constants.Z_FUNCTION ) { return false; } var zobject = getters.getZObjectAsJson; Iif ( !zobject || !zobject[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_FUNCTION_ARGUMENTS ] ) { return false; } var argumentList = zobject[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_FUNCTION_ARGUMENTS ]; // Remove argument type argumentList.shift(); return argumentList.length > 0 && argumentList.every( function ( arg ) { var argumentTypeIsSet = !!arg[ Constants.Z_ARGUMENT_TYPE ] && !!arg[ Constants.Z_ARGUMENT_TYPE ][ Constants.Z_REFERENCE_ID ], argumentMonolingualStringIsSet = arg[ Constants.Z_ARGUMENT_LABEL ][ Constants.Z_MULTILINGUALSTRING_VALUE ] .filter( function ( label ) { return label[ Constants.Z_MONOLINGUALSTRING_VALUE ] && label[ Constants.Z_MONOLINGUALSTRING_VALUE ][ Constants.Z_STRING_VALUE ] !== ''; } ).length > 0; return argumentTypeIsSet && argumentMonolingualStringIsSet; } ); }, currentZFunctionHasOutput: function ( state, getters ) { if ( getters.getCurrentZObjectType !== Constants.Z_FUNCTION ) { return false; } var zobject = getters.getZObjectAsJson; return zobject && !!zobject[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_FUNCTION_RETURN_TYPE ][ Constants.Z_REFERENCE_ID ]; }, currentZFunctionHasTesters: function ( state, getters ) { if ( getters.getCurrentZObjectType !== Constants.Z_FUNCTION ) { return false; } var zobject = getters.getZObjectAsJson; return zobject && zobject[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_FUNCTION_TESTERS ].length > 0; }, currentZFunctionHasImplementations: function ( state, getters ) { if ( getters.getCurrentZObjectType !== Constants.Z_FUNCTION ) { return false; } var zobject = getters.getZObjectAsJson; return zobject && zobject[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_FUNCTION_IMPLEMENTATIONS ].length > 0; }, currentZObjectLanguages: function ( state, getters ) { var languageList = []; if ( !getters.getZObjectAsJson ) { return; } addLanguagesFromNameLabels( getters, languageList ); addLanguagesFromArgumentLabels( getters, languageList ); addLanguagesFromAliasLabels( getters, languageList ); return languageList.map( function ( languageCode ) { return { Z1K1: Constants.Z_REFERENCE, [ Constants.Z_REFERENCE_ID ]: languageCode }; } ) || []; }, /** * Return the boolean value, equivalend to if currentZObjectId is placeholder * * @param {Object} state * @param {Object} getters * @return {boolean} isNewZObject */ isNewZObject: function ( state, getters ) { return getters.getCurrentZObjectId === Constants.NEW_ZID_PLACEHOLDER; } } }; |