-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
116 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Почему значения нужно рекурсивно копировать? | ||
|
||
Может возникнуть вопрос, почему в форме у нас есть переменная values, которая является чистым хранилищем | ||
значений, почему нельзя реализовать её как гетер и проходить по всем зависимостям и получать их значение. | ||
Это решение позволяет обойти 2 проблемы: | ||
|
||
1. При удалении поля для ввода - будет теряться его значение | ||
2. Как поступать, если в начале мы инициализировали форму `form.setValues(data)`, а затем добавили input. | ||
|
||
Именно данная подход сосредоточить модель в одном месте, позволяет упростить разработку. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {Form, FormProxy} from "../../plugin"; | ||
|
||
describe("Default test For FormProxy", () => { | ||
|
||
test("Values of parent form should be changed", () => { | ||
const parentForm = new Form(); | ||
|
||
const form = new FormProxy({ | ||
name: "address" | ||
}) | ||
parentForm.subscribe(form); | ||
|
||
parentForm.setValues({ | ||
name: "jenesius" | ||
}) | ||
|
||
form.change({ | ||
city: "XXX" | ||
}) | ||
expect(parentForm.values).toEqual({ | ||
address: { | ||
city: "XXX" | ||
}, | ||
name: "jenesius" | ||
}) | ||
expect(parentForm.changes).toEqual({ | ||
address: { | ||
city: "XXX" | ||
} | ||
}) | ||
}) | ||
test("Changed prop must be true after change", () => { | ||
const parentForm = new Form(); | ||
|
||
const form = new FormProxy({ | ||
name: "address" | ||
}) | ||
parentForm.subscribe(form); | ||
|
||
expect(form.changed).toBe(false); | ||
expect(parentForm.changed).toBe(false); | ||
|
||
form.change({ | ||
city: "XXX" | ||
}) | ||
|
||
expect(parentForm.changed).toBe(true) | ||
expect(form.changed).toBe(true); | ||
|
||
}) | ||
/* | ||
test("New values after setValues", () => { | ||
const parentForm = new Form(); | ||
const form = new FormProxy({ | ||
name: "address" | ||
}) | ||
parentForm.subscribe(form); | ||
form.setValues({ | ||
planet: "Earth" | ||
}) | ||
expect(parentForm.values).toEqual({ | ||
address: { | ||
planet: "Earth" | ||
} | ||
}) | ||
})*/ | ||
}) |