Skip to content

Commit

Permalink
Merge pull request #7546 from jonboiser/remove-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
jonboiser committed Oct 7, 2020
2 parents 4b92725 + 218125a commit 4cf820b
Showing 1 changed file with 0 additions and 66 deletions.
66 changes: 0 additions & 66 deletions kolibri/core/assets/src/kolibri_app.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit 4cf820b

Please sign in to comment.