From 218125a32762ea17ebba1dab15d6ca2c6f8c1b38 Mon Sep 17 00:00:00 2001 From: Jonathan Boiser Date: Tue, 6 Oct 2020 14:56:19 -0700 Subject: [PATCH] Remove schema validation from KolibriApp --- kolibri/core/assets/src/kolibri_app.js | 66 -------------------------- 1 file changed, 66 deletions(-) diff --git a/kolibri/core/assets/src/kolibri_app.js b/kolibri/core/assets/src/kolibri_app.js index d1d61e7e780..eae477e3f29 100644 --- a/kolibri/core/assets/src/kolibri_app.js +++ b/kolibri/core/assets/src/kolibri_app.js @@ -1,6 +1,5 @@ import { sync } from 'vuex-router-sync'; import forEach from 'lodash/forEach'; -import isPlainObject from 'lodash/isPlainObject'; import router from 'kolibri.coreVue.router'; import logger from 'kolibri.lib.logging'; import Vue from 'kolibri.lib.vue'; @@ -10,59 +9,6 @@ import KolibriModule from 'kolibri_module'; export const logging = logger.getLogger(__filename); -function _registerSchema(schema, moduleName, subPaths = []) { - forEach(schema, (subSchema, propertyName) => { - // Must be a plain object to be a valid schema spec - // And have at least a default key, and one of type or validator - if (isPlainObject(subSchema)) { - if ( - typeof subSchema.default !== 'undefined' && - (subSchema.type || (subSchema.validator && subSchema.validator instanceof Function)) - ) { - /* eslint-disable no-inner-declarations */ - function getter(state) { - if (moduleName) { - state = state[moduleName]; - } - subPaths.forEach(path => { - state = state[path]; - }); - return state[propertyName]; - } - function callback(newValue) { - let fail = false; - if (subSchema.type) { - if (subSchema.type === Object) { - if (!isPlainObject(newValue)) { - fail = true; - } - } else { - fail = !(newValue instanceof subSchema.type); - } - } - if (subSchema.validator) { - if (!subSchema.validator(newValue)) { - fail = true; - } - } - if (fail) { - logging.error( - `Validation failed for property: ${[...subPaths, propertyName]} in module ${ - moduleName ? moduleName : 'root' - }` - ); - } - } - /* eslint-enable */ - store.watch(getter, callback); - } else { - // Otherwise assume it is just a nested object structure - _registerSchema(subSchema, moduleName, [...subPaths, propertyName]); - } - } - }); -} - /* * A class for single page apps that control routing and vuex state. * Override the routes, mutations, initialState, and RootVue getters. @@ -132,18 +78,6 @@ export default class KolibriApp extends KolibriModule { store.registerModule(name, module); }); - if (process.env.NODE_ENV !== 'production') { - // Register any schemas we have defined for vuex state - if (this.pluginModule.state && this.pluginModule.state.schema) { - _registerSchema(this.pluginModule.state.schema); - } - forEach(this.pluginModule.modules, (module, name) => { - if (module.schema) { - _registerSchema(module.schema, name); - } - }); - } - return heartbeat.startPolling().then(() => { this.store.dispatch('getNotifications'); return Promise.all([