Skip to content

Switcher#42

Open
Kanonir87 wants to merge 6 commits intoroistat:masterfrom
Kanonir87:Switcher
Open

Switcher#42
Kanonir87 wants to merge 6 commits intoroistat:masterfrom
Kanonir87:Switcher

Conversation

@Kanonir87
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/Switcher/Switcher.jsx
import React, { PropTypes } from 'react';

export default class Switcher extends React.Component {
static propTypes = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

даваем ему сделаем внутреннее состояние isChecked и надо не забыть про componentWillReceiveProps

Comment thread src/Switcher/Switcher.jsx Outdated
}
}

const styles = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо переслать на StyleSheet.create({})

Comment thread src/Switcher/story.jsx
import StateProvider from '../StateProvider';

storiesOf('Switcher', module)
.add('Switcher', () => (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавить кейс где он без внешнего состояния переключается

Comment thread src/Switcher/Switcher.jsx
import React, { PropTypes } from 'react';

export default class Switcher extends React.Component {
static propTypes = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай добавил onChange и isDisabled

Comment thread src/Switcher/Switcher.jsx Outdated

this.state = {
isChecked: props.isChecked,
isDisabled: props.isDisabled
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isDisabled не надо держать в стейте, достаточно получения через props

Comment thread src/Switcher/Switcher.jsx
this._onClickHandler = this._onClickHandler.bind(this);
this._onChangeHandler = this._onChangeHandler.bind(this);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно добавить обновление стейта на componentWillReceiveProps

Comment thread src/Switcher/Switcher.jsx Outdated

getDefaultRenderProps() {
return {
onChange: this._onChangeHandler,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onChange не нужен

Comment thread src/Switcher/Switcher.jsx Outdated
getDefaultRenderProps() {
return {
onChange: this._onChangeHandler,
onClick: this._onClickHandler
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onClick можно сразу в rendere навесить

Comment thread src/Switcher/Switcher.jsx Outdated
const props = this.props;

if (!props.isDisabled) {
this.setState({ isChecked: !this.state.isChecked });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.setState({ isChecked: !this.state.isChecked }, () => {
    props.onClick && props.onClick(event); 
    props.onChange && props.onChange(this.state.isChecked);
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants