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>
);
import { login } from './loginDucks';
class UserForm extends Component {
...
handleSubmit = e => {
this.props.login(this.state.form);
}
...
render() {
const { isLoading, isError, shouldRedirect } = this.props;
if (shouldRedirect) <Redirect to="/index" >;
return (
...
);
}
}
const mapStateToProps = state => ({
isLoading: state.login.isLoading,
isError: state.login.isError,
shouldRedirect: state.login.shouldRedirect,
});
const mapDispatchToProps = {
login,
};
export default connect(mapStateToProps, mapDispatchToProps)(UserForm);
const LOGIN_REQUEST = 'LOGIN_REQUEST';
const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
const LOGIN_ERROR = 'LOGIN_ERROR';
const loginSuccess = data => ({
type: LOGIN_SUCCESS,
payload: data,
});
const loginError = data => ({
type: LOGIN_ERROR,
});
export const login = form => async dispatch => {
try {
const res = await axios.post('/api/user', form);
if (!res.data) dispatch(loginError());
dispatch(loginSuccess());
} catch e {
dspatch(loginError());
}
}
const initialState = {
isLoading: false,
isError: false,
shouldRedirect: false,
};
export default (state = initialState, action) => {
const { type, payload } = action;
switch(type) {
case LOGIN_REQUEST:
return {
...state,
isLoading: true,
isError: false,
};
case LOGIN_SUCCESS:
return {
...state,
isLoading: false,
shouldRedirect: false,
};
case LOGIN_ERROR:
return {
...state,
isLoading: false,
isError: true,
};
default:
return state;
}
};
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, combineReducers, compose, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { Route, Switch } from 'react-router';
import { BrowserRouter } from 'react-router-dom';
import Auth from './component/AuthForm';
import Helmet from './aplication';
import loginReducer from './loginDucks';
function user(state = {}, action){
if(action.type === 'ADD_USER'){
return [
...state,
action.user
];
}
return state;
}
const rootReducer = combineReducers({
login: loginReducer,
user,
});
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(rootReducer, composeEnhancers(
applyMiddleware(thunk),
));
ReactDOM.render(
<div>
...
</div>,
document.getElementById('content')
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,
});
}
}
);
margin: 0 auto;
. flex-wrap: wrap
. Но тогда у колонок помимо flex: 0 0 {value}%;
, определите max-width: {value}%;
, чтобы сетка не сыпалась..cotainer {
width: $my-width-value;
width: 100%;
margin: 0 auto;
padding-right: 15px;
padding-left: 15px;
}
.row {
display: flex;
flex-wrap: wrap;
margin-left: -15px;
margin-right: -15px;
}
.col {
flex: 0 0 $col-width:
max-width: $col-width:
padding-right: 15px;
padding-left: 15px;
}
const { date: TodayDate, transactions } = this.state;
const TodayDate = this.state.date;
const transactions = this.state.transactions;
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));
class Example extends React.Component {
handleClick = e => {
alert(`
target: ${e.target.tagName}
currentTarget: ${e.currentTarget.tagName}
`);
};
render() {
return <button onClick={this.handleClick}><p>click me</p></button>;
}
}
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);
function withLog(WrappedComponent) {
return class extends React.Component {
displayName = WrappedComponent.displayName || WrappedComponent.name;
componentDidMount() {
console.log(`[${this.displayName}]: componentDidMount`);
}
...
render() {
console.log(`[${this.displayName}]: render`);
return <WrappedComponent {...this.props} />;
}
}
}
class MyComp extends React.Component {
...
}
const MyCompWithLog = withLog(MyComp);
this.method = function () {
return this.arr.reduce((acc, fn) => acc.then(fn), Promise.resolve());
}
export const addComponent = data => {
return async function(dispatch) { // тут добавлен return и аргумент
let comps = await fire.database().ref("components");
comps.push({
name: data.component,
comp: data.component_name
});
//так же в любое время вы можете вызвать dispatch
dispatch({ type: 'someAction', payload: 'someValue' });
};
}
const foo = x => y => x + y;
const foo = x => {
return y => {
return x + y;
}
};
const foo = x => y => x + y;
const a = x(5);
const b = a(6);
console.log(b);
// => 11
y => 5 + y;
export const addComponent = data => async dispatch => {
let comps = await fire.database().ref("components");
// функция продолжит выполнение только когда вернется значение присвамваемое comps
comps.push({
name: data.component,
comp: data.component_name
});
};