Skip to content

Commit 49fc634

Browse files
authored
Rename cloneIfObject to protectAgainstParamReassignment; Fix isObject (#391)
* Improve isObject; Rename cloneIfObject to protectAgainstParamReassignment * Just give up and import lodash.isPlainObject * Update Travis targets
1 parent 761b3ef commit 49fc634

21 files changed

+1148
-997
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
language: node_js
22
sudo: false
33
node_js:
4-
- '10'
4+
- 'node'
5+
- 'lts/*'
56
before_install:
67
- npm install -g yarn
78
script:

API.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,7 @@ optionally validate the inputs by passing `true` as the second argument.
237237
```jsx
238238
class MyForm extends React.Component {
239239
render() {
240-
return (
241-
<Formsy preventDefaultSubmit>
242-
...
243-
</Formsy>
244-
);
240+
return <Formsy preventDefaultSubmit>...</Formsy>;
245241
}
246242
}
247243
```

__tests__/Formsy-spec.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ describe('Update a form', () => {
469469
}
470470
const form = mount(<TestForm />);
471471
const FoundForm = form.find(TestForm);
472-
const submitEvent = {preventDefault: jest.fn()};
472+
const submitEvent = { preventDefault: jest.fn() };
473473
FoundForm.simulate('submit', submitEvent);
474474
expect(submitEvent.preventDefault).toHaveBeenCalled();
475475
});
@@ -486,12 +486,11 @@ describe('Update a form', () => {
486486
}
487487
const form = mount(<TestForm />);
488488
const FoundForm = form.find(TestForm);
489-
const submitEvent = {preventDefault: jest.fn()};
489+
const submitEvent = { preventDefault: jest.fn() };
490490
FoundForm.simulate('submit', submitEvent);
491491
expect(submitEvent.preventDefault).not.toHaveBeenCalled();
492492
});
493493

494-
495494
it('should trigger an onValidSubmit when submitting a valid form', () => {
496495
const isCalled = jest.fn();
497496

__tests__/Utils-spec.tsx

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
import * as utils from '../src/utils';
22

3-
const VALUES = [
4-
undefined,
5-
null,
6-
'',
7-
0,
8-
100,
9-
'Hello',
10-
'Goodbye',
11-
{ foo: 'bar' },
12-
{ foo: 'lounge' },
13-
[{ foo: ['bar'] }],
14-
[{ foo: [] }],
15-
['a', 7],
16-
['a', 8],
17-
['a', 7, 7],
18-
new Date(1000),
19-
new Date(2000),
20-
() => 2 + 2,
21-
() => 2 + 3,
22-
utils.noop,
23-
];
24-
253
function getReadable(value, index) {
264
return `${typeof value} at ${index}`;
275
}
286

7+
const TYPES = {
8+
isArray: [[], [{ foo: ['bar'] }], [{ foo: [] }], ['a', 7], ['a', 8], ['a', 7, 7]],
9+
isDate: [new Date(1000), new Date(2000)],
10+
isFunction: [() => 2 + 2, () => 2 + 3, utils.noop],
11+
isNumber: [0, 100, 0.4],
12+
isObject: [{}, { foo: 'bar' }, { foo: 'lounge' }],
13+
isString: ['', 'Hello', 'Goodbye'],
14+
isTypeUndefined: [undefined],
15+
};
16+
17+
const VALUES = [
18+
null,
19+
...TYPES.isArray,
20+
...TYPES.isDate,
21+
...TYPES.isFunction,
22+
...TYPES.isNumber,
23+
...TYPES.isObject,
24+
...TYPES.isString,
25+
...TYPES.isTypeUndefined,
26+
];
27+
2928
describe('Utils', () => {
29+
// For each function in types
30+
Object.keys(TYPES).forEach(isFn => {
31+
// Create a test for that functiojn
32+
it(isFn, () => {
33+
// For each value in values
34+
VALUES.forEach(value => {
35+
// Make sure that if it is in that types TYPES array, it returns true
36+
expect(utils[isFn](value)).toBe(TYPES[isFn].includes(value));
37+
});
38+
});
39+
});
40+
3041
// For every value in values, run isSame(a, b) with every other value in the array.
3142
// Expect isSame to return true only if you are at the same point in the array.
3243
VALUES.forEach((a, idxa) => {

dist/FormsyContext.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import React from 'react';
2+
import { FormsyContextInterface } from './interfaces';
3+
declare const _default: React.Context<FormsyContextInterface>;
4+
export default _default;

dist/Wrapper.d.ts

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,55 @@
1-
import React from 'react';
2-
import PropTypes from 'prop-types';
3-
import { RequiredValidation, Validations } from './interfaces';
4-
declare const propTypes: {
5-
innerRef: PropTypes.Requireable<(...args: any[]) => any>;
6-
name: PropTypes.Validator<string>;
7-
required: PropTypes.Requireable<string | boolean | object>;
8-
validations: PropTypes.Requireable<string | object>;
9-
value: PropTypes.Requireable<any>;
10-
};
11-
export interface WrapperProps<V> {
12-
innerRef?: (ref: any) => void;
13-
name: string;
14-
required?: RequiredValidation<V>;
15-
validationError?: any;
16-
validationErrors?: any;
17-
validations?: Validations<V>;
18-
value?: V;
19-
}
20-
export interface WrapperState<V> {
21-
[key: string]: unknown;
22-
externalError: null;
23-
formSubmitted: boolean;
24-
isPristine: boolean;
25-
isRequired: boolean;
26-
isValid: boolean;
27-
pristineValue: any;
28-
validationError: any[];
29-
value: V;
30-
}
31-
export interface InjectedProps<V> {
32-
errorMessage: any;
33-
errorMessages: any;
34-
hasValue: boolean;
35-
isFormDisabled: boolean;
36-
isFormSubmitted: boolean;
37-
isPristine: boolean;
38-
isRequired: boolean;
39-
isValid: boolean;
40-
isValidValue: (value: V) => boolean;
41-
ref?: any;
42-
resetValue: any;
43-
setValidations: any;
44-
setValue: (value: V) => void;
45-
showError: boolean;
46-
showRequired: boolean;
47-
}
48-
export declare type PassDownProps<V> = WrapperProps<V> & InjectedProps<V>;
49-
export { propTypes };
50-
export default function <T, V>(WrappedComponent: React.ComponentType<T & PassDownProps<V>>): React.ComponentType<Omit<T & WrapperProps<V>, keyof InjectedProps<V>>>;
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { RequiredValidation, Validations } from './interfaces';
4+
declare const propTypes: {
5+
innerRef: PropTypes.Requireable<(...args: any[]) => any>;
6+
name: PropTypes.Validator<string>;
7+
required: PropTypes.Requireable<string | boolean | object>;
8+
validations: PropTypes.Requireable<string | object>;
9+
value: PropTypes.Requireable<any>;
10+
};
11+
export interface WrapperProps<V> {
12+
innerRef?: (ref: any) => void;
13+
name: string;
14+
required?: RequiredValidation<V>;
15+
validationError?: any;
16+
validationErrors?: any;
17+
validations?: Validations<V>;
18+
value?: V;
19+
}
20+
export interface WrapperState<V> {
21+
[key: string]: unknown;
22+
externalError: null;
23+
formSubmitted: boolean;
24+
isPristine: boolean;
25+
isRequired: boolean;
26+
isValid: boolean;
27+
pristineValue: any;
28+
validationError: any[];
29+
value: V;
30+
}
31+
export interface InjectedProps<V> {
32+
errorMessage: any;
33+
errorMessages: any;
34+
hasValue: boolean;
35+
isFormDisabled: boolean;
36+
isFormSubmitted: boolean;
37+
isPristine: boolean;
38+
isRequired: boolean;
39+
isValid: boolean;
40+
isValidValue: (value: V) => boolean;
41+
ref?: any;
42+
resetValue: () => void;
43+
setValidations: (validations: Validations<V>, required: RequiredValidation<V>) => void;
44+
setValue: (value: V) => void;
45+
showError: boolean;
46+
showRequired: boolean;
47+
}
48+
export interface WrapperInstanceMethods {
49+
isValid: () => boolean;
50+
getValue: () => any;
51+
getErrorMessage: () => any;
52+
}
53+
export declare type PassDownProps<V> = WrapperProps<V> & InjectedProps<V>;
54+
export { propTypes };
55+
export default function <T, V>(WrappedComponent: React.ComponentType<T & PassDownProps<V>>): React.ComponentType<Omit<T & WrapperProps<V>, keyof InjectedProps<V>>>;

0 commit comments

Comments
 (0)