Skip to content

Commit

Permalink
fix: #340 onDel calling onAdd handler
Browse files Browse the repository at this point in the history
  • Loading branch information
foxhound87 committed Nov 16, 2017
1 parent 3619f92 commit de3c09a
Show file tree
Hide file tree
Showing 30 changed files with 129 additions and 78 deletions.
10 changes: 0 additions & 10 deletions .eslintrc

This file was deleted.

14 changes: 14 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parser: babel-eslint
extends: airbnb-base
plugins:
- import

rules:
react/forbid-prop-types: 0
class-methods-use-this: 0
function-paren-newline: 0
no-confusing-arrow: 0
padded-blocks: 0
quote-props:
- error
- consistent-as-needed
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"ajv": "^5.2.2",
"babel-cli": "6.23.0",
"babel-core": "6.23.1",
"babel-eslint": "7.1.1",
"babel-eslint": "8.0.2",
"babel-loader": "6.3.2",
"babel-plugin-add-module-exports": "0.2.1",
"babel-plugin-lodash": "3.2.11",
Expand All @@ -77,19 +77,17 @@
"codecov": "1.0.1",
"commitizen": "2.9.6",
"cz-conventional-changelog": "^2.0.0",
"eslint": "3.15.0",
"eslint-config-airbnb": "14.1.0",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsx-a11y": "4.0.0",
"eslint-plugin-react": "6.10.0",
"eslint": "4.11.0",
"eslint-config-airbnb-base": "12.1.0",
"eslint-plugin-import": "2.8.0",
"husky": "0.13.1",
"json-loader": "0.5.4",
"mobx": "^3.0.0",
"mocha": "3.2.0",
"npm-run-all": "4.0.1",
"nyc": "^10.2.0",
"rimraf": "2.5.4",
"semantic-release": "^6.3.6",
"semantic-release": "^8.2.0",
"validator": "^8.0.0",
"validatorjs": "^3.13.3",
"webpack": "1.*.*"
Expand Down
3 changes: 1 addition & 2 deletions src/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
hasIntKeys } from './utils';

export default class Base {

noop = () => {};

execHook = (name, fallback = {}) => $try(
Expand Down Expand Up @@ -96,7 +95,7 @@ export default class Base {
Event Handler: On Del
*/
onDel = (...args) =>
this.execHandler('onAdd', args, (e, path) => {
this.execHandler('onDel', args, (e, path) => {
e.preventDefault();
this.del($isEvent(path) ? this.path : path);
});
Expand Down
12 changes: 7 additions & 5 deletions src/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export default class Field extends Base {

@observable files;

constructor({ key, path, data = {}, props = {}, update = false, state }) {
constructor({
key, path, data = {}, props = {}, update = false, state,
}) {
super();

this.state = state;
Expand Down Expand Up @@ -306,8 +308,8 @@ export default class Field extends Base {
this.$changed = true;

const $get = $ => $isBool($, this.value)
? $.target.checked
: $.target.value;
? $.target.checked
: $.target.value;

// assume "v" or "e" are the values
if (_.isNil(e) || _.isNil(e.target)) {
Expand Down Expand Up @@ -359,7 +361,7 @@ export default class Field extends Base {

this.files = files || args;
}));
}
}

/**
Prototypes
Expand Down Expand Up @@ -454,7 +456,7 @@ export const prototypes = {
},

checkDVRValidationPlugin() {
const drivers = this.state.form.validator.drivers;
const { drivers } = this.state.form.validator;
if (_.isNil(drivers.dvr) && !_.isNil(this.rules)) {
// eslint-disable-next-line
console.warn(
Expand Down
6 changes: 4 additions & 2 deletions src/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export default class Form extends Base {
this.$handlers = handlers;

// load data from initializers methods
const initial = _.each({ setup, options, plugins, bindings },
(val, key) => _.isFunction(this[key])
const initial = _.each({
setup, options, plugins, bindings,
},
(val, key) => _.isFunction(this[key])
? _.merge(val, this[key].apply(this, [this]))
: val);

Expand Down
4 changes: 3 additions & 1 deletion src/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export default class State {
fields: {},
};

constructor({ form, initial, options, bindings }) {
constructor({
form, initial, options, bindings,
}) {
this.set('form', form);
this.initProps(initial);
this.options = new Options();
Expand Down
6 changes: 4 additions & 2 deletions src/Validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class Validator {
this.checkSVKValidationPlugin();
}

initDrivers(drivers) {
initDrivers(drivers) { // eslint-disable-next-line
_.map(drivers, (Class, key) => this.plugins[key] &&
(this.drivers[key] = new Class(this.plugins[key], {
schema: (key === 'svk') ? this.schema : null,
Expand Down Expand Up @@ -92,7 +92,9 @@ export default class Validator {
}

@action
validateField({ field = null, path, showErrors = false, related = false }) {
validateField({
field = null, path, showErrors = false, related = false,
}) {
const instance = field || this.form.select(path);
// check if the field is a valid instance
if (!instance.path) throw new Error('Validation Error: Invalid Field Instance');
Expand Down
17 changes: 11 additions & 6 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const parsePath = (path) => {
return $path;
};

const parseInput = (input, { type, isEmptyArray, separated, unified, initial }) =>
const parseInput = (input, {
type, isEmptyArray, separated, unified, initial,
}) =>
input(utils.$try(separated, unified, initial, defaultValue({ type, isEmptyArray })));

// make integers labels empty
Expand Down Expand Up @@ -160,9 +162,12 @@ TO:
*/
const reduceValuesToUnifiedFields = values =>
_.reduce(values, (obj, value, key) =>
Object.assign(obj, { [key]: { value,
fields: mapNestedValuesToUnifiedValues(value),
} }), {});
Object.assign(obj, {
[key]: {
value,
fields: mapNestedValuesToUnifiedValues(value),
},
}), {});

/*
Fallback Unified Props to Sepated Mode
Expand All @@ -171,7 +176,7 @@ const handleFieldsPropsFallback = (fields, initial) => {
if (!_.has(initial, 'values')) return fields;
// if the 'values' object is passed in constructor
// then update the fields definitions
let values = initial.values;
let { values } = initial;
if (utils.hasUnifiedProps({ fields })) {
values = reduceValuesToUnifiedFields(values);
}
Expand All @@ -180,7 +185,7 @@ const handleFieldsPropsFallback = (fields, initial) => {

const mergeSchemaDefaults = (fields, validator) => {
if (validator) {
const properties = validator.schema.properties;
const { properties } = validator.schema;
if (_.isEmpty(fields) && !!properties) {
_.each(properties, (prop, key) => {
_.set(fields, key, {
Expand Down
1 change: 1 addition & 0 deletions src/shared/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default {
if ($throw && $err) this.invalidate();
return handler;
})
// eslint-disable-next-line
.then(action(() => (this.$submitting = false)))
.catch(action((err) => {
this.$submitting = false;
Expand Down
4 changes: 3 additions & 1 deletion src/shared/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default {
/**
MobX Event (observe/intercept)
*/
MOBXEvent({ path = null, key = 'value', call, type }) {
MOBXEvent({
path = null, key = 'value', call, type,
}) {
const $instance = this.select(path || this.path, null, null) || this;

const $call = change => call.apply(null, [{
Expand Down
10 changes: 6 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const props = {
},
};

const checkObserveItem = change => ({ key, to, type, exec }) =>
const checkObserveItem = change => ({
key, to, type, exec,
}) =>
(change.type === type && change.name === key && change.newValue === to)
&& exec.apply(change, [change]);

Expand Down Expand Up @@ -108,7 +110,7 @@ const isArrayOfObjects = fields =>
_.isArray(fields) && _.every(fields, _.isPlainObject);

const $getKeys = fields =>
_.union(_.map(_.values(fields), values => _.keys(values))[0]);
_.union(_.map(_.values(fields), values => _.keys(values))[0]);

const hasUnifiedProps = ({ fields }) =>
!isStruct({ fields }) && hasProps('field', $getKeys(fields));
Expand All @@ -128,7 +130,7 @@ const allowNested = (field, strictProps) =>
]) || strictProps);

const parseIntKeys = fields =>
_.map(fields.keys(), _.ary(parseInt, 1));
_.map(fields.keys(), _.ary(parseInt, 1));

const hasIntKeys = fields =>
_.every(parseIntKeys(fields), _.isInteger);
Expand Down Expand Up @@ -156,7 +158,7 @@ const $isBool = ($, val) =>
const $try = (...args) => {
let found = null;

args.map(val =>
args.map(val => // eslint-disable-line
((found === null) && !_.isNil(val))
&& (found = val));

Expand Down
2 changes: 1 addition & 1 deletion src/validators/DVR.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class DVR {

validateField(field, form) {
// get form fields data
const data = {};
const data = {}; // eslint-disable-next-line
form.each($field => (data[$field.path] = $field.validatedValue));
this.validateFieldAsync(field, form, data);
this.validateFieldSync(field, form, data);
Expand Down
4 changes: 3 additions & 1 deletion tests/computed/_.flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import isDirty from './flat.isDirty';
import isEmpty from './flat.isEmpty';
import isPristine from './flat.isPristine';

export default { isValid, hasError, isDirty, isEmpty, isPristine };
export default {
isValid, hasError, isDirty, isEmpty, isPristine,
};
4 changes: 3 additions & 1 deletion tests/data/forms/fixes/form.i.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@ class NewForm extends Form {
}
}

export default new NewForm({ fields, rules, defaults, initials, types }, { name: 'Fixes-I' });
export default new NewForm({
fields, rules, defaults, initials, types,
}, { name: 'Fixes-I' });
8 changes: 5 additions & 3 deletions tests/data/forms/flat/form.a.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const fields = {
devSkills: {
label: 'Dev Skills',
value: 5,
input: value => value.toString(), // (user to store)
output: value => Number(value), // (store to user)
input: value => value.toString(), // (user to store)
output: value => Number(value), // (store to user)
},
revenue: {
label: 'Revenue (Billion $)',
Expand All @@ -75,7 +75,9 @@ const schema = {
type: 'object',
properties: {
// username: { type: 'string', minLength: 6, maxLength: 20 },
email: { type: 'string', format: 'email', minLength: 5, maxLength: 20 },
email: {
type: 'string', format: 'email', minLength: 5, maxLength: 20,
},
password: { type: 'string', minLength: 6, maxLength: 20 },
terms: { enum: [true, false] },
devSkills: { range: [5, 10] },
Expand Down
4 changes: 3 additions & 1 deletion tests/data/forms/flat/form.c.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const schema = {
type: 'object',
properties: {
username: { type: 'string', minLength: 6, maxLength: 20 },
email: { type: 'string', format: 'email', minLength: 5, maxLength: 20 },
email: {
type: 'string', format: 'email', minLength: 5, maxLength: 20,
},
password: { type: 'string', minLength: 6, maxLength: 20 },
devSkills: { range: [1, 10] },
},
Expand Down
4 changes: 3 additions & 1 deletion tests/data/forms/flat/form.d.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const schema = {
type: 'object',
properties: {
username: { type: 'string', minLength: 6, maxLength: 20 },
email: { type: 'string', format: 'email', minLength: 5, maxLength: 20 },
email: {
type: 'string', format: 'email', minLength: 5, maxLength: 20,
},
password: { type: 'string', minLength: 6, maxLength: 20 },
terms: { enum: [true, false] },
devSkills: { range: [1, 10], exclusiveRange: true },
Expand Down
4 changes: 3 additions & 1 deletion tests/data/forms/flat/form.f.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ const schema = {
type: 'object',
properties: {
username: { type: 'string', minLength: 6, maxLength: 20 },
email: { type: 'string', format: 'email', minLength: 5, maxLength: 20 },
email: {
type: 'string', format: 'email', minLength: 5, maxLength: 20,
},
password: { type: 'string', minLength: 6, maxLength: 20 },
devSkills: { range: [5, 10] },
},
Expand Down
4 changes: 3 additions & 1 deletion tests/data/forms/flat/form.i.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const schema = {
type: 'object',
properties: {
username: { type: 'string', minLength: 6, maxLength: 20 },
email: { type: 'string', format: 'email', minLength: 5, maxLength: 20 },
email: {
type: 'string', format: 'email', minLength: 5, maxLength: 20,
},
password: { type: 'string', minLength: 6, maxLength: 20 },
},
};
Expand Down
8 changes: 6 additions & 2 deletions tests/data/forms/flat/form.l.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ const schema = {
$async: true,
type: 'object',
properties: {
username: { type: 'string', minLength: 6, maxLength: 20, checkUser: 'user' },
email: { type: 'string', format: 'email', minLength: 5, maxLength: 20 },
username: {
type: 'string', minLength: 6, maxLength: 20, checkUser: 'user',
},
email: {
type: 'string', format: 'email', minLength: 5, maxLength: 20,
},
password: { type: 'string', minLength: 6, maxLength: 20 },
},
};
Expand Down
4 changes: 3 additions & 1 deletion tests/data/forms/flat/form.m.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const schema = {
type: 'object',
properties: {
username: { type: 'string', minLength: 6, maxLength: 20 },
email: { type: 'string', format: 'email', minLength: 5, maxLength: 20 },
email: {
type: 'string', format: 'email', minLength: 5, maxLength: 20,
},
password: { type: 'string', minLength: 6, maxLength: 20 },
},
};
Expand Down
4 changes: 3 additions & 1 deletion tests/data/forms/flat/form.n.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const schema = {
type: 'object',
properties: {
username: { type: 'string', minLength: 6, maxLength: 20 },
email: { type: 'string', format: 'email', minLength: 5, maxLength: 20 },
email: {
type: 'string', format: 'email', minLength: 5, maxLength: 20,
},
password: { type: 'string', minLength: 6, maxLength: 20 },
},
};
Expand Down
4 changes: 3 additions & 1 deletion tests/data/forms/nested/form.n.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ class NewForm extends Form {
}
}

export default new NewForm({ fields, values, input, output, placeholders, bindings }, { name: 'Nested-N' });
export default new NewForm({
fields, values, input, output, placeholders, bindings,
}, { name: 'Nested-N' });
Loading

0 comments on commit de3c09a

Please sign in to comment.