Skip to content

Commit 03d1813

Browse files
author
Larry Botha
authored
Merge pull request tjinauyeung#84 from tjinauyeung/chore/update-deps
2 parents 3a41bba + e82fac4 commit 03d1813

File tree

8 files changed

+2917
-4299
lines changed

8 files changed

+2917
-4299
lines changed

lib/components/Field.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
value={$form[name]}
1515
on:change={handleChange}
1616
on:blur={handleChange}
17-
{...$$props} />
17+
{...$$props}
18+
/>

lib/components/Form.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@
4545
{handleChange}
4646
{handleSubmit}
4747
{updateField}
48-
{updateTouched} />
48+
{updateTouched}
49+
/>
4950
</form>

lib/components/Select.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
value={$form[name]}
1313
on:change={handleChange}
1414
on:blur={handleChange}
15-
{...$$props}>
15+
{...$$props}
16+
>
1617
<slot />
1718
</select>

lib/create-form.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const createForm = (config) => {
1212
let initialValues = config.initialValues || {};
1313

1414
const validationSchema = config.validationSchema;
15-
const validateFn = config.validate;
15+
const validateFunction = config.validate;
1616
const onSubmit = config.onSubmit;
1717

1818
const getInitial = {
@@ -73,10 +73,10 @@ export const createForm = (config) => {
7373
});
7474
}
7575

76-
if (validateFn) {
76+
if (validateFunction) {
7777
isValidating.set(true);
7878
return Promise.resolve()
79-
.then(() => validateFn({[field]: value}))
79+
.then(() => validateFunction({[field]: value}))
8080
.then((errs) =>
8181
util.update(errors, field, !util.isNullish(errs) ? errs[field] : ''),
8282
)
@@ -101,19 +101,19 @@ export const createForm = (config) => {
101101
return updateValidateField(field, value);
102102
}
103103

104-
function handleSubmit(ev) {
105-
if (ev && ev.preventDefault) {
106-
ev.preventDefault();
104+
function handleSubmit(event) {
105+
if (event && event.preventDefault) {
106+
event.preventDefault();
107107
}
108108

109109
isSubmitting.set(true);
110110

111111
return util.subscribeOnce(form).then((values) => {
112-
if (typeof validateFn === 'function') {
112+
if (typeof validateFunction === 'function') {
113113
isValidating.set(true);
114114

115115
return Promise.resolve()
116-
.then(() => validateFn(values))
116+
.then(() => validateFunction(values))
117117
.then((error) => {
118118
if (util.isEmpty(error)) {
119119
clearErrorsAndSubmit(values);
@@ -137,7 +137,7 @@ export const createForm = (config) => {
137137
if (yupErrors && yupErrors.inner) {
138138
const updatedErrors = getInitial.errors();
139139

140-
yupErrors.inner.forEach((error) =>
140+
yupErrors.inner.map((error) =>
141141
util.set(updatedErrors, error.path, error.message),
142142
);
143143

lib/util.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ function isEmpty(object) {
2929
function getValues(object) {
3030
let result = [];
3131
for (const [, value] of Object.entries(object)) {
32-
result = result.concat(
33-
typeof value === 'object' ? getValues(value) : value,
34-
);
32+
result = [...result, typeof value === 'object' ? getValues(value) : value];
3533
}
3634
return result;
3735
}
@@ -102,12 +100,16 @@ function set(object, path, value) {
102100

103101
const result = path
104102
.slice(0, -1)
103+
// TODO: replace this reduce with something more readable
104+
// eslint-disable-next-line unicorn/no-array-reduce
105105
.reduce(
106106
(accumulator, key, index) =>
107107
new Object(accumulator[key]) === accumulator[key]
108108
? accumulator[key]
109109
: (accumulator[key] =
110-
Math.abs(path[index + 1]) >> 0 === +path[index + 1] ? [] : {}),
110+
Math.trunc(Math.abs(path[index + 1])) === +path[index + 1]
111+
? []
112+
: {}),
111113
object,
112114
);
113115

0 commit comments

Comments
 (0)