Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change import style of 'ajv' and 'lodash' in all non test files #1242

Merged
merged 2 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
rankWith,
uiTypeIs
} from '@jsonforms/core';
import * as _ from 'lodash';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { NgRedux } from '@angular-redux/store';
import { JsonFormsBaseRenderer } from '@jsonforms/angular';
Expand Down
4 changes: 2 additions & 2 deletions packages/angular-material/src/other/label.renderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from 'lodash';
import has from 'lodash/has';
import { NgRedux } from '@angular-redux/store';
import { Component } from '@angular/core';
import { JsonFormsBaseRenderer } from '@jsonforms/angular';
Expand Down Expand Up @@ -56,7 +56,7 @@ const mapStateToProps = (
state: JsonFormsState,
ownProps: OwnPropsOfRenderer
) => {
const visible = _.has(ownProps, 'visible')
const visible = has(ownProps, 'visible')
? ownProps.visible
: isVisible(ownProps, state);

Expand Down
7 changes: 4 additions & 3 deletions packages/angular-material/src/other/master-detail/master.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import some from 'lodash/some';
import get from 'lodash/get';
import { Component } from '@angular/core';
import * as _ from 'lodash';
import { JsonFormsControl } from '@jsonforms/angular';
import { NgRedux } from '@angular-redux/store';
import {
Expand All @@ -19,7 +20,7 @@ const keywords = ['#', 'properties', 'items'];
export const removeSchemaKeywords = (path: string) => {
return path
.split('/')
.filter(s => !_.some(keywords, key => key === s))
.filter(s => !some(keywords, key => key === s))
.join('.');
};

Expand Down Expand Up @@ -161,7 +162,7 @@ export class MasterListComponent extends JsonFormsControl {
controlElement.options.labelRef
);
const masterItem = {
label: _.get(d, labelRefInstancePath),
label: get(d, labelRefInstancePath),
data: d,
path: `${instancePath}.${index}`,
schema: resolvedSchema,
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/jsonforms.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import * as _ from 'lodash';
import maxBy from 'lodash/maxBy';
import {
ComponentFactoryResolver,
ComponentRef,
Expand Down Expand Up @@ -90,7 +90,7 @@ export class JsonFormsOutlet extends JsonFormsBaseRenderer<UISchemaElement>
const schema: JsonSchema = this.schema || props.schema;
const uischema = this.uischema || props.uischema;

const renderer = _.maxBy(renderers, r => r.tester(uischema, schema));
const renderer = maxBy(renderers, r => r.tester(uischema, schema));
let bestComponent: Type<any> = UnknownRenderer;
if (renderer !== undefined && renderer.tester(uischema, schema) !== -1) {
bestComponent = renderer.renderer;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import AJV from 'ajv';
import { RankedTester } from '../testers';
import { JsonSchema, UISchemaElement } from '../';
import { generateDefaultUISchema, generateJsonSchema } from '../generators';
import { UISchemaTester } from '../reducers/uischemas';
import * as AJV from 'ajv';
import { AnyAction, Dispatch } from 'redux';

export const INIT: 'jsonforms/INIT' = 'jsonforms/INIT';
Expand Down
49 changes: 25 additions & 24 deletions packages/core/src/generators/uischema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import * as _ from 'lodash';

import isEmpty from 'lodash/isEmpty';
import isArray from 'lodash/isArray';
import head from 'lodash/head';
import startCase from 'lodash/startCase';
import keys from 'lodash/keys';
import { JsonSchema } from '../models/jsonSchema';
import {
ControlElement,
Expand Down Expand Up @@ -51,32 +54,30 @@ const createLayout = (layoutType: string): Layout => ({
* @returns {boolean}
*/
const isUnionType = (jsonSchema: JsonSchema): boolean =>
!_.isEmpty(jsonSchema) &&
!_.isEmpty(jsonSchema.type) &&
_.isArray(jsonSchema.type);
!isEmpty(jsonSchema) && !isEmpty(jsonSchema.type) && isArray(jsonSchema.type);

/**
* Derives the type of the jsonSchema element
*/
const deriveType = (jsonSchema: JsonSchema): string => {
if (
!_.isEmpty(jsonSchema) &&
!_.isEmpty(jsonSchema.type) &&
!isEmpty(jsonSchema) &&
!isEmpty(jsonSchema.type) &&
typeof jsonSchema.type === 'string'
) {
return jsonSchema.type;
}
if (isUnionType(jsonSchema)) {
return _.head(jsonSchema.type);
return head(jsonSchema.type);
}
if (
!_.isEmpty(jsonSchema) &&
(!_.isEmpty(jsonSchema.properties) ||
!_.isEmpty(jsonSchema.additionalProperties))
!isEmpty(jsonSchema) &&
(!isEmpty(jsonSchema.properties) ||
!isEmpty(jsonSchema.additionalProperties))
) {
return 'object';
}
if (!_.isEmpty(jsonSchema) && !_.isEmpty(jsonSchema.items)) {
if (!isEmpty(jsonSchema) && !isEmpty(jsonSchema.items)) {
return 'array';
}

Expand Down Expand Up @@ -109,7 +110,7 @@ const wrapInLayoutIfNecessary = (
uischema: UISchemaElement,
layoutType: string
): Layout => {
if (!_.isEmpty(uischema) && !isLayout(uischema)) {
if (!isEmpty(uischema) && !isLayout(uischema)) {
const verticalLayout: Layout = createLayout(layoutType);
verticalLayout.elements.push(uischema);

Expand All @@ -127,8 +128,8 @@ const wrapInLayoutIfNecessary = (
* The name of the schema
*/
const addLabel = (layout: Layout, labelName: string) => {
if (!_.isEmpty(labelName)) {
const fixedLabel = _.startCase(labelName);
if (!isEmpty(labelName)) {
const fixedLabel = startCase(labelName);
if (isGroup(layout)) {
layout.label = fixedLabel;
} else {
Expand All @@ -149,10 +150,10 @@ const addLabel = (layout: Layout, labelName: string) => {
*/
const isCombinator = (jsonSchema: JsonSchema): boolean => {
return (
!_.isEmpty(jsonSchema) &&
(!_.isEmpty(jsonSchema.oneOf) ||
!_.isEmpty(jsonSchema.anyOf) ||
!_.isEmpty(jsonSchema.allOf))
!isEmpty(jsonSchema) &&
(!isEmpty(jsonSchema.oneOf) ||
!isEmpty(jsonSchema.anyOf) ||
!isEmpty(jsonSchema.allOf))
);
};

Expand All @@ -164,7 +165,7 @@ const generateUISchema = (
layoutType: string,
rootSchema?: JsonSchema
): UISchemaElement => {
if (!_.isEmpty(jsonSchema) && jsonSchema.$ref !== undefined) {
if (!isEmpty(jsonSchema) && jsonSchema.$ref !== undefined) {
return generateUISchema(
resolveSchema(rootSchema, jsonSchema.$ref),
schemaElements,
Expand All @@ -177,7 +178,7 @@ const generateUISchema = (

if (isCombinator(jsonSchema)) {
const controlObject: ControlElement = createControlElement(
_.startCase(schemaName),
startCase(schemaName),
currentRef
);
schemaElements.push(controlObject);
Expand All @@ -192,11 +193,11 @@ const generateUISchema = (
const layout: Layout = createLayout(layoutType);
schemaElements.push(layout);

if (jsonSchema.properties && _.keys(jsonSchema.properties).length > 1) {
if (jsonSchema.properties && keys(jsonSchema.properties).length > 1) {
addLabel(layout, schemaName);
}

if (!_.isEmpty(jsonSchema.properties)) {
if (!isEmpty(jsonSchema.properties)) {
// traverse properties
const nextRef: string = currentRef + '/properties';
Object.keys(jsonSchema.properties).map(propName => {
Expand Down Expand Up @@ -228,7 +229,7 @@ const generateUISchema = (
/* falls through */
case 'boolean':
const controlObject: ControlElement = createControlElement(
_.startCase(schemaName),
startCase(schemaName),
currentRef
);
schemaElements.push(controlObject);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/reducers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import * as _ from 'lodash';
import merge from 'lodash/merge';
import { SET_CONFIG, SetConfigAction } from '../actions';
import { configDefault } from '../configDefault';

const applyDefaultConfiguration = (config: any = {}) =>
_.merge({}, configDefault, config);
merge({}, configDefault, config);

export const configReducer = (
state = applyDefaultConfiguration(),
Expand Down
26 changes: 12 additions & 14 deletions packages/core/src/reducers/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import * as _ from 'lodash';
import cloneDeep from 'lodash/cloneDeep';
import set from 'lodash/set';
import get from 'lodash/get';
import filter from 'lodash/filter';
import { ErrorObject, ValidateFunction } from 'ajv';
import {
INIT,
Expand Down Expand Up @@ -126,7 +129,7 @@ export const coreReducer = (
return state;
} else if (action.path === '') {
// empty path is ok
const result = action.updater(_.cloneDeep(state.data));
const result = action.updater(cloneDeep(state.data));

if (result === undefined || result === null) {
return {
Expand All @@ -146,17 +149,13 @@ export const coreReducer = (
errors
};
} else {
const oldData: any = _.get(state.data, action.path);
const oldData: any = get(state.data, action.path);
let newData = action.updater(oldData);
if (newData === '') {
newData = undefined;
}

const newState: any = _.set(
_.cloneDeep(state.data),
action.path,
newData
);
const newState: any = set(cloneDeep(state.data), action.path, newData);
const errors = sanitizeErrors(state.validator, newState);

return {
Expand All @@ -173,14 +172,13 @@ export const coreReducer = (
}
};

export const extractData = (state: JsonFormsCore) => _.get(state, 'data');
export const extractSchema = (state: JsonFormsCore) => _.get(state, 'schema');
export const extractUiSchema = (state: JsonFormsCore) =>
_.get(state, 'uischema');
export const extractData = (state: JsonFormsCore) => get(state, 'data');
export const extractSchema = (state: JsonFormsCore) => get(state, 'schema');
export const extractUiSchema = (state: JsonFormsCore) => get(state, 'uischema');
export const errorAt = (instancePath: string) => (
state: JsonFormsCore
): any[] => {
return _.filter(
return filter(
state.errors,
(error: ErrorObject) => error.dataPath === instancePath
);
Expand All @@ -190,7 +188,7 @@ export const subErrorsAt = (instancePath: string) => (
): any[] => {
const path = `${instancePath}.`;

return _.filter(state.errors, (error: ErrorObject) =>
return filter(state.errors, (error: ErrorObject) =>
error.dataPath.startsWith(path)
);
};
18 changes: 9 additions & 9 deletions packages/core/src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import get from 'lodash/get';
import {
defaultDataReducer,
extractDefaultData,
Expand All @@ -31,7 +32,6 @@ import { combineReducers, Reducer } from 'redux';
import { JsonFormsRendererRegistryEntry, rendererReducer } from './renderers';
import { fieldReducer } from './fields';
import { configReducer } from './config';
import * as _ from 'lodash';
import {
coreReducer,
errorAt,
Expand Down Expand Up @@ -71,18 +71,18 @@ export const jsonformsReducer = (
});

export const getData = (state: JsonFormsState) =>
extractData(_.get(state, 'jsonforms.core'));
extractData(get(state, 'jsonforms.core'));
export const getSchema = (state: JsonFormsState): JsonSchema =>
extractSchema(_.get(state, 'jsonforms.core'));
extractSchema(get(state, 'jsonforms.core'));
export const getUiSchema = (state: JsonFormsState): UISchemaElement =>
extractUiSchema(_.get(state, 'jsonforms.core'));
extractUiSchema(get(state, 'jsonforms.core'));
export const getDefaultData = (
state: JsonFormsState
): JsonFormsDefaultDataRegistryEntry[] =>
extractDefaultData(_.get(state, 'jsonforms.defaultData'));
extractDefaultData(get(state, 'jsonforms.defaultData'));
export const getRenderers = (
state: JsonFormsState
): JsonFormsRendererRegistryEntry[] => _.get(state, 'jsonforms.renderers');
): JsonFormsRendererRegistryEntry[] => get(state, 'jsonforms.renderers');

export const findUISchema = (state: JsonFormsState) => (
schema: JsonSchema,
Expand Down Expand Up @@ -130,13 +130,13 @@ export const getSubErrorsAt = (instancePath: string) => (
export const getConfig = (state: JsonFormsState) => state.jsonforms.config;

export const getLocale = (state: JsonFormsState) =>
fetchLocale(_.get(state, 'jsonforms.i18n'));
fetchLocale(get(state, 'jsonforms.i18n'));

export const getLocalizedSchema = (locale: string) => (
state: JsonFormsState
): JsonSchema => findLocalizedSchema(locale)(_.get(state, 'jsonforms.i18n'));
): JsonSchema => findLocalizedSchema(locale)(get(state, 'jsonforms.i18n'));

export const getLocalizedUISchema = (locale: string) => (
state: JsonFormsState
): UISchemaElement =>
findLocalizedUISchema(locale)(_.get(state, 'jsonforms.i18n'));
findLocalizedUISchema(locale)(get(state, 'jsonforms.i18n'));
7 changes: 4 additions & 3 deletions packages/core/src/reducers/uischemas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as _ from 'lodash';
import maxBy from 'lodash/maxBy';
import remove from 'lodash/remove';
import {
ADD_UI_SCHEMA,
AddUISchemaAction,
Expand Down Expand Up @@ -26,7 +27,7 @@ export const uischemaRegistryReducer = (
.concat({ tester: action.tester, uischema: action.uischema });
case REMOVE_UI_SCHEMA:
const copy = state.slice();
_.remove(copy, entry => entry.tester === action.tester);
remove(copy, entry => entry.tester === action.tester);
return copy;
default:
return state;
Expand All @@ -40,7 +41,7 @@ export const findMatchingUISchema = (
schemaPath: string,
path: string
): UISchemaElement => {
const match = _.maxBy(state, entry =>
const match = maxBy(state, entry =>
entry.tester(jsonSchema, schemaPath, path)
);
if (
Expand Down
Loading