import { fetchInitialDataApi } from './api';
const FETCH_INITIAL_DATA_REQUEST = 'FETCH_INITIAL_DATA_REQUEST';
const FETCH_INITIAL_DATA_SUCCESS = 'FETCH_INITIAL_DATA_SUCCESS';
const FETCH_INITIAL_DATA_ERROR = 'FETCH_INITIAL_DATA_ERROR';
const fetchInitialDataRequest = () => ({ type: FETCH_INITIAL_DATA_REQUEST });
const fetchInitialDataSuccess = data => ({
type: FETCH_INITIAL_DATA_SUCCES,
payload: data,
});
const fetchInitialDataError = error => ({
type: FETCH_INITIAL_DATA_ERROR,
payload: error,
});
const fetchInitialData => async dispatch => {
try {
dispatch(fetchInitialDataRequest());
const { data } = await fetchInitialDataApi();
dispatch(fetchInitialDataSuccess(data));
} catch error {
dispatch(fetchInitialDataError(error));
}
};
const initialState = {
data: {},
isLoading: false,
isError: false,
error: null,
};
export default function(state = initialState, action) {
const { type, payload } = action;
switch (type) {
case FETCH_INITIAL_DATA_REQUEST:
return {
...state,
isLoading: true,
isError: false,
error: null,
};
case FETCH_INITIAL_DATA_SUCCESS:
return {
...state,
data: payload,
isLoading: false,
};
case FETCH_INITIAL_DATA_ERROR:
return {
...state,
isLoading: false,
isError: true,
error: payload,
};
default:
return state;
}
}
export default (state = window._data) => state;
const a = {
b() {
this.с();
},
c() {
alert('expected result');
}
}
const d = {
b: a.b.bind(a),
c() {
alert('wow');
}
};
d.b(); // => "expected result"
var obj = {
a: function() {
// do something
},
b: function() {
// do something
}
};
const obj = {
a() {
// do something
},
b() {
// do something
}
};
const options = [
{
value: 'wifi',
title: 'WiFi',
},
{
value: 'isBT',
title: 'BT',
},
];
class Expample extends Component {
state = {
switch = '',
};
handleChange = e => {
const { name, value } = e.target;
this.setState({
[name]: value,
});
};
render() {
return (
<Wrapper>
<SwitchGroup
onChange={this.handleChange}
name="switch"
value={this.state.switch}
options={options}
/>
</Wrapper>
);
}
}
class SwitchGroup extends Component {
...
handleClick(value) {
const { name, onChange } = this.props;
...
onChange({
e: {
target {
name,
value,
},
}
});
}
render() {
return(
<Wrapper>
{this.props.options.map((el, i) => (
<Switch
key={i}
onClick={() => handleClick(el.value)}
isActive={el.value === this.props.value}
...
>
{el.title}
</Switch>
))}
<Wrapper />
);
}
}
componentWillReceiveProps({ isOpen, article, loadArticleComments }) {
loadArticleComments(article.id)
}
componentWillReceiveProps({ isOpen, article, loadArticleComments }) {
if (
!article.commentsLoaded &&
!article.commentsLoading &&
!this.props.isOpen &&
isOpen
) {
loadArticleComments(article.id)
}
}
case "LOAD_ARTICLE_COMMENTS_SUCCESS": {
return articleState
.setIn(["entities", action.payload.articleId, "commentsLoading"], false)
.setIn(["entities", action.payload.articleId, "commentsLoaded"], true);
}
return (
<div>
<h5>{comment.user}</h5>
{comment.text}
</div>
);
export const getReq = data => (
async dispatch => {
try {
dispatch({
type: types.GET_REQUEST,
});
let res = await api.getReq(data);
dispatch({
type: types.GET_SUCCESS,
payload: res,
});
res = await api.getReq2(data);
} catch (error) {
dispatch({
type: types.GET_ERROR,
});
}
}
);
export const getReq = data => (
async dispatch => {
try {
dispatch({
type: types.GET_REQUEST,
});
const res = await api.getReq(data);
dispatch({
type: types.GET_SUCCESS,
payload: res,
});
dispatch(req2(res));
} catch (error) {
dispatch({
type: types.GET_ERROR,
});
}
}
);
var sell = [
{"breed": "sosna", "size": "20x100x6000", "cost": 1500},
{"breed": "sosna", "size": "30x100x6000", "cost": 2500},
{"breed": "sosna", "size": "40x100x6000", "cost": 3500},
{"breed": "sosna", "size": "20x100x6000", "cost": 4500},
{"breed": "sosna", "size": "30x100x6000", "cost": 5500},
{"breed": "sosna", "size": "40x100x6000", "cost": 6500},
];
var breed = ["sosna"];
var size = ["30x100x6000", "20x100x6000"];
var params = { breed, size };
var activeKeys = Object.keys(params).filter(function(key) {
return params[key].length;
});
var filtered = sell.filter(function(item) {
return activeKeys.every(function(key) {
return params[key].indexOf(item[key]) != -1;
});
});
const sell = [
{"breed": "sosna", "size": "20x100x6000", "cost": 1500},
{"breed": "sosna", "size": "30x100x6000", "cost": 2500},
{"breed": "sosna", "size": "40x100x6000", "cost": 3500},
{"breed": "sosna", "size": "20x100x6000", "cost": 4500},
{"breed": "sosna", "size": "30x100x6000", "cost": 5500},
{"breed": "sosna", "size": "40x100x6000", "cost": 6500},
];
const breed = ["sosna"];
const size = ["30x100x6000", "20x100x6000"];
const params = { breed, size };
const activeKeys = Object.keys(params).filter(key => params[key].length);
const filtered =
sell.filter(item => activeKeys.every(key => params[key].includes(item[key])));
var min = sell.reduce(function(acc, el) {
return acc < el.cost ? acc : el.cost;
}, Infinity);
var values = sell.map(function(el) {
return el.cost;
});
var min = Math.min.apply(Math, values);
const min = sell.reduce((acc, el) => acc < el.cost ? acc : el.cost, Infinity);
const min = Math.min(...sell.map(el => el.cost));
const Menu = {
el: document.getElementById('js-main-menu'),
btn: document.getElementById('js-main-menu__btn'),
init() {
this.toggle = this.toggle.bind(this);
this.close = this.close.bind(this);
this.open = this.open.bind(this);
this.btn.addEventListener('click', this.toggle);
},
toggle() {
this.el.style.display =
!this.el.style.display || this.el.style.display === 'block' ? 'none' : 'block';
},
open() {
this.el.style.display = 'block';
},
close() {
this.el.style.display = 'none';
}
}
export default Menu;
import Menu from './Menu';
const closeButton = document.getElementById('js-close-button');
const openButton = document.getElementById('js-open-button');
Menu.init();
closeButton.addEventListener('click', Menu.close);
openButton.addEventListener('click', Menu.open);
class Menu {
constructor({ el, btn }) {
this.el = document.getElementById(el);
this.el = document.getElementById(btn);
this.toggle = this.toggle.bind(this);
this.close = this.close.bind(this);
this.open = this.open.bind(this);
this.btn.addEventListener('click', this.toggle);
}
...
}
export default Menu;
import Menu from './Menu';
const closeButton = document.getElementById('js-close-button');
const openButton = document.getElementById('js-open-button');
const menu = new Menu({
el: 'js-main-menu',
btn: 'js-main-menu__btn',
});
closeButton.addEventListener('click', menu.close);
openButton.addEventListener('click', menu.open);
this.method = function () {
return this.arr.reduce((acc, fn) => acc.then(fn), Promise.resolve());
}
this.state.title.map((item, i) => (
<TodoList
key={i}
index={i}
deleteItem={descriptionArr[i]}
title={titleArr[i]}
deleteItem={this.deleteItem}
/>
))
[
{
title: 'title',
description: 'description',
},
{
title: 'title',
description: 'description',
},
{
title: 'title',
description: 'description',
}
]
Иногда на функции checkResult скрипт не может получить ответ от сайта и он выполняет третье условие и перезапускает функцию checkResult снова.
console.log(last_read);
console.log(getRead());
console.log(last_read < getread());
console.log(last_read > getread());
function checkResult(last_read) {
setTimeout(function() {
if (last_read < getread()) {
} else if (last_read > getread()) {
} else {
checkResult(last_read);
}
checkResult(getRead());
}, 500);
}