Skip to content

Commit

Permalink
Refactor #930
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Jun 20, 2019
1 parent 9738a50 commit daca920
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/components/messages/Messages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ interface MessagesProps {
export class Messages extends React.Component<MessagesProps, any> {
public show(message: Message | Message[]): void;
public clear(): void;
public replace(message: Message | Message[]): void;
}
9 changes: 3 additions & 6 deletions src/components/messages/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ export class Messages extends Component {
})
}

replace(messages) {
this.setState(
{
replace(value) {
this.setState({
messages: [],
},
() => this.show(messages)
);
}, () => this.show(value));
}

onClose(message) {
Expand Down
10 changes: 10 additions & 0 deletions src/showcase/messages/MessagesDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ showMultiple() {
{`
this.messages.clear();
`}
</CodeHighlight>

<h3>Replacing Messages</h3>
<p><i>replace(newMessages)</i> method adds new messages after removing all old messages.</p>

<CodeHighlight className="language-jsx">
{`
this.messages.replace(newMessages);
`}
</CodeHighlight>

Expand Down

0 comments on commit daca920

Please sign in to comment.