itemsAmount = itemsAmount - itemCoast; // из общей суммы корзины вычитаем стоимость товара
{this.state.data[0].title}
render() {
const { data } = this.state;
const isAllDataReady = data && data.length > 0;
return (
<div>
{!isAllDataReady && <Preloader />}
{isAllDataReady && (
<div>
<h4>App component</h4>
{data[0].title}
</div>
)}
</div>
);
}
function DateGetTime() {
CHECK_DATE(this);
return UTC_DATE_VALUE(this);
}
CHECK_DATE(arg) = (%_ClassOf(arg) === 'Date' ? %_ValueOf(arg) : ThrowDateTypeError());
function SpaceDate(...args) {
var date;
date = new Date(...args);
date.__proto__ = SpaceDate.prototype;
return date;
}
SpaceDate.prototype.__proto__ = Date.prototype;
SpaceDate.prototype.test = function() {
return this;
};
$(document).on('focusout', 'input', function(){
var name = $(this).attr('name');
var value = $(this).val();
$('input[name=' + name + ']').val(value);
});
var diff = Math.min(Math.abs(x - y), 360 - Math.abs(x - y));
var getDiff = (x, y) => Math.min(Math.abs(x - y), 360 - Math.abs(x - y));
Cannot convert undefined or null to object
import React from 'react';
import { connect } from 'react-redux';
export class Balance extends React.Component {
// some code
}
const mapStateToProps = ({ total }) => ({ total });
export default connect(mapStateToProps)(Balance);
import { Balance } from './Balance';
import Balance from './Balance';
import React from 'react';
import { shallow, mount } from 'enzyme';
import { expect } from 'chai';
import { Balance } from '../app/containers/balance/src/balance';
describe('<Balance />', () => {
it('Balance test', function () {
const mockTotal = { /* mock code */ };
const wrapper = shallow(<Balance total={mockTotal} />);
expect(wrapper.contains(<h3>Мои балансы</h3>)).to.equal(true);
});
});
npm install
npm run build:example
npm run build:browser
imagesLoaded(document.body, { background: true }, () =>
document.body.classList.remove('loading'));
const piecesObj = new Pieces(document.querySelector('.slideshow > .pieces'), {
pieces: {rows: 22, columns: 20},
delay: [0,60],
hasTilt: true,
tilt: {
maxRotationX: -1,
maxRotationY: -1,
maxTranslationX: -5,
maxTranslationY: -2
}
});
let isAnimating = false;
const openImage = () => {
isAnimating = true;
piecesObj.animate({
duration: 400,
easing: 'easeOutQuad',
autoplay: true,
delay: (t,i,l) => {
return parseInt(t.dataset.row) * parseInt(t.dataset.delay);
},
translateX: (t,i) => {
return anime.random(-500,500)+'px';
},
translateY: (t,i) => {
return anime.random(-800,-200)+'px';
},
rotateZ: (t,i) => {
return anime.random(-45,45)+'deg';
},
opacity: 0,
complete: () => {
piecesObj.setImage(imgsrc);
piecesObj.animate({
duration: 500,
easing: [0.3,1,0.3,1],
delay: (t,i,l) => {
return parseInt(t.dataset.row) * parseInt(t.dataset.delay);
},
translateX: 0,
translateY: () => {
return [anime.random(200,800)+'px','0px'];
},
rotateZ: 0,
opacity: {
value: 1,
duration: 500,
easing: 'linear'
},
complete: () => {
isAnimating = false;
}
});
}
});
};
document.addEventListener('DOMContentLoaded', openImage);
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
tweets: []
};
}
getData = () => {
axios.post('/', {
username: this.state.username
})
.then(({data: tweets}) => {
console.log(tweets)
this.setState({ tweets });
})
.catch(console.error);
};
render () {
const { tweets } = this.state;
console.log(tweets.length);
if (tweets.length > 0 && tweets[0].user) {
console.log(tweets.length);
return (
<div>
<header>
<Form getData={this.getData} />
</header>
<main>
<User user={tweets[0].user} />
{tweets.map((tweet, i) => <Tweet key={i} tweet={tweet} />)}
</main>
</div>
);
} else {
return (
<Form getData={this.getData} />
);
}
}
}
constructor(props) {
super(props);
this.state = {
tweets: []
};
this.getData = this.getData.bind(this);
}
class Capture extends React.Component {
constructor(props) {
super(props);
this.state = {
form: {
username: '',
},
tweets: [],
}
this.onFormSubmit = this.onFormSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
}
onFormSubmit(e) {
e.preventDefault()
axios.post('/', {
username: this.state.form.username
})
.then(({data: tweets}) => {
this.setState({ tweets });
})
.catch(console.error);
}
handleChange(event) {
const { form } = this.state;
form.username = event.target.value;
this.setState({ form });
}
render () {
const { tweets } = this.state;
return (
<div>
<form onSubmit={this.onFormSubmit}>
<p className="leadform-component-container">
<input
type="text"
placeholder="Username"
required
onChange={this.handleChange}
/>
</p>
<p className="leadform-component-container">
<input type="submit" value="Press me" />
</p>
</form>
<div>
{tweets.map((tweet, i) => <Tweet key={i} tweet={tweet} />)}
</div>
</div>
)
}
}
ReactDOM.render(<Capture />, document.getElementById("app"));
clickHandle(e) {
// some code
}
clickHandle = e => {
// some code
};
constructor(props) {
super(props);
this.clickHandle = this.clickHandle.bind(this);
}
<SomeComponent onClick={() => this.сlickHandle()} /> // контекст не будет потерян
<ListItem
key={item.id}
onClick={e => this.сlickHandle(item.id, e)}
>
{item.name}
</ListItem>
var john = {
firstName: 'John',
getName() {
return this.firstName; // this - контекст вызова и это не всегда наш объект
}
}
console.log(john.getName()); // john
var foo = {
firstName: 'foo',
};
var foo.getName = john.getName;
console.log(foo.getName()); // foo
var bar = john.getName;
console.log(bar()); // undefined
Cannot read property 'firstName' of undefined
<Route path="/stories/:slug" component={Stories}/>