Skip to content

Commit 7230d3f

Browse files
committed
state вынесен в отдельный модуль
1 parent aa6b901 commit 7230d3f

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/js/model.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,9 @@ import onChange from "on-change";
22
import * as yup from "yup";
33
import i18next from "../i18n.js";
44

5-
import { renderErrors, renderInputValue } from "./view.js";
5+
import createState from './state.js';
66

7-
const object = {
8-
inputValue: "",
9-
rssFeed: [],
10-
errors: null,
11-
};
12-
13-
const state = onChange(object, (path, value) => {
14-
console.log(`состояние изменено: ${path}`, value);
15-
if (path === "rssFeed") {
16-
console.log("rss feed:", value);
17-
}
18-
if (path === "inputValue") {
19-
renderInputValue(value);
20-
}
21-
if (path === "errors") {
22-
renderErrors(value);
23-
}
24-
});
7+
const state = createState();
258

269
const schema = yup
2710
.string()

src/js/state.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import onChange from "on-change";
2+
import { renderErrors, renderInputValue } from "./view.js";
3+
4+
const createState = () => {
5+
const object = {
6+
inputValue: "",
7+
rssFeed: [],
8+
errors: null,
9+
};
10+
11+
const state = onChange(object, (path, value) => {
12+
console.log(`состояние изменено: ${path}`, value);
13+
if (path === "rssFeed") {
14+
console.log("rss feed:", value);
15+
}
16+
if (path === "inputValue") {
17+
renderInputValue(value);
18+
}
19+
if (path === "errors") {
20+
renderErrors(value);
21+
}
22+
});
23+
24+
return state;
25+
};
26+
27+
export default createState;

0 commit comments

Comments
 (0)