Skip to content

Commit

Permalink
fix: #364 #471
Browse files Browse the repository at this point in the history
  • Loading branch information
foxhound87 committed Jan 16, 2019
1 parent e7b7a98 commit 0e25565
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 62 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"parser": "babel-eslint",
"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"
]
}
}
14 changes: 0 additions & 14 deletions .eslintrc.yml

This file was deleted.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"cover": "nyc npm test",
"coverage:check": "nyc check-coverage --satements 95 --branches 80 --functions 95 --lines 95",
"coverage:report": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"semantic-release": "semantic-release",
"postinstall": "opencollective postinstall"
"semantic-release": "semantic-release"
},
"repository": {
"type": "git",
Expand All @@ -55,15 +54,14 @@
"umd"
],
"engines": {
"node": ">=6.0.0"
"node": ">=8.0.0"
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
},
"dependencies": {
"opencollective": "^1.0.3",
"lodash": "^4.16.2"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/Base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed } from 'mobx';
import { computed } from 'mobx3';
import _ from 'lodash';

import {
Expand Down
2 changes: 1 addition & 1 deletion src/Field.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { observable, observe, action, computed, isObservableArray, toJS, asMap, untracked } from 'mobx';
import { observable, observe, action, computed, isObservableArray, toJS, asMap, untracked } from 'mobx3';
import _ from 'lodash';
import Base from './Base';

Expand Down
2 changes: 1 addition & 1 deletion src/Form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action, computed, observable, asMap } from 'mobx';
import { action, computed, observable, asMap } from 'mobx3';
import _ from 'lodash';

import Base from './Base';
Expand Down
2 changes: 1 addition & 1 deletion src/Options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { observable, action, toJS, extendObservable, set } from 'mobx';
import { observable, action, toJS, extendObservable, set } from 'mobx3';
import _ from 'lodash';
import { uniqueId } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion src/State.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { observe } from 'mobx';
import { observe } from 'mobx3';
import _ from 'lodash';

import Options from './Options';
Expand Down
2 changes: 1 addition & 1 deletion src/Validator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action, observable } from 'mobx';
import { action, observable } from 'mobx3';
import _ from 'lodash';

import { $try } from './utils';
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useStrict, configure } from 'mobx';
import { useStrict, configure } from 'mobx3';

import Form, { prototypes as formPrototypes } from './Form';
import Field, { prototypes as fieldPrototypes } from './Field';
Expand Down
2 changes: 1 addition & 1 deletion src/shared/Actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action } from 'mobx';
import { action } from 'mobx3';
import _ from 'lodash';
import utils from '../utils';
import parser from '../parser';
Expand Down
2 changes: 1 addition & 1 deletion src/shared/Events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { observe, intercept } from 'mobx';
import { observe, intercept } from 'mobx3';
import _ from 'lodash';
import utils from '../utils';
import parser from '../parser';
Expand Down
2 changes: 1 addition & 1 deletion src/shared/Initializer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action } from 'mobx';
import { action } from 'mobx3';
import _ from 'lodash';
import utils from '../utils';
import parser from '../parser';
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import { values as mobxValues, keys as mobxKeys } from 'mobx';
import { values as mobxValues, keys as mobxKeys } from 'mobx3';

const props = {
booleans: ['hasError', 'isValid', 'isDirty', 'isPristine', 'isDefault', 'isEmpty', 'focused', 'touched', 'changed', 'disabled', 'resetting', 'clearing'],
Expand Down
38 changes: 16 additions & 22 deletions src/validators/DVR.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,7 @@ export default class DVR {
this.validateFieldSync(field, form, data);
}

validateFieldSync(field, form, data) {
const $rules = this.rules(field.rules, 'sync');
// exit if no rules found
if (_.isEmpty($rules[0])) return;
// get field rules
const rules = { [field.path]: $rules };
// create the validator instance
const Validator = this.validator;
const validation = new Validator(data, rules);
// set label into errors messages instead key
makeLabels(validation, field, form) {
const labels = { [field.path]: field.label };
_.each(validation.rules[field.path], (rule) => {
if (typeof rule.value === 'string' && rule.name.match(/^(required_|same)/)) {
Expand All @@ -74,7 +65,21 @@ export default class DVR {
});
}
});

validation.setAttributeNames(labels);
}

validateFieldSync(field, form, data) {
const $rules = this.rules(field.rules, 'sync');
// exit if no rules found
if (_.isEmpty($rules[0])) return;
// get field rules
const rules = { [field.path]: $rules };
// create the validator instance
const Validator = this.validator;
const validation = new Validator(data, rules);
// set label into errors messages instead key
this.makeLabels(validation, field, form);
// check validation
if (validation.passes()) return;
// the validation is failed, set the field error
Expand All @@ -91,18 +96,7 @@ export default class DVR {
const Validator = this.validator;
const validation = new Validator(data, rules);
// set label into errors messages instead key
const labels = { [field.path]: field.label };
_.each(validation.rules[field.path], (rule) => {
if (typeof rule.value === 'string' && rule.name.match(/^(required_|same)/)) {
_.each(rule.value.split(','), (p) => {
const f = form.$(p);
if (f && f.path && f.label) {
labels[f.path] = f.label;
}
});
}
});
validation.setAttributeNames(labels);
this.makeLabels(validation, field, form);

const $p = new Promise(resolve =>
validation.checkAsync(
Expand Down
2 changes: 1 addition & 1 deletion src/validators/VJF.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import { toJS } from 'mobx';
import { toJS } from 'mobx3';
import utils from '../utils';

/**
Expand Down
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4388,11 +4388,6 @@ [email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkd
version "5.0.3"
resolved "https://registry.yarnpkg.com/mobx/-/mobx-5.0.3.tgz#53b97f2a0f9b0dd7774c96249f81bf2d513d8e1c"

[email protected]:
version "5.0.0"
resolved "https://registry.yarnpkg.com/mobx/-/mobx-5.0.0.tgz#1214db984899b937581a5e802c65cec214eb6dd1"
integrity sha512-stLRfRPsXpHeRDgfhW5QvyIz7PXU2ti60l5Pe+hl2XGxtQdCxV3b90w5eU2nUP6tha9+kozihQclpMWqh+kzSw==

[email protected]:
version "3.2.0"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.2.0.tgz#7dc4f45e5088075171a68896814e6ae9eb7a85e3"
Expand Down Expand Up @@ -6279,11 +6274,6 @@ uid-number@^0.0.6, uid-number@~0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81"

undefined@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/undefined/-/undefined-0.1.0.tgz#9b706a4b32ad30c20ca4fe65ddcbbbdac32bded0"
integrity sha1-m3BqSzKtMMIMpP5l3cu72sMr3tA=

underscore@~1.4.4:
version "1.4.4"
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.4.4.tgz#61a6a32010622afa07963bf325203cf12239d604"
Expand Down

0 comments on commit 0e25565

Please sign in to comment.