Skip to content

Commit f2722b6

Browse files
authored
Chore/action exports (#41)
* Add .vscode to gitignore * Add test for action exports * Add action imports to example * Add action import examples to readme
1 parent 1103df6 commit f2722b6

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ example/dist
2929
*.sublime-*
3030
.idea/
3131
*.DS_Store
32+
.vscode

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Dispatch notification actions from any other component:
103103
import React, {PropTypes} from 'react';
104104
import ReactDOM from 'react-dom';
105105

106-
import Notifications from 'react-notification-system-redux';
106+
import Notifications, { success } from 'react-notification-system-redux';
107107

108108
const notificationOpts = {
109109
// uid: 'once-please', // you can specify your own uid if required
@@ -127,7 +127,7 @@ class OtherComponent extends React.Component {
127127

128128
handleClick() {
129129
this.context.store.dispatch(
130-
Notifications.success(notificationOpts)
130+
success(notificationOpts)
131131
);
132132
}
133133

@@ -165,6 +165,18 @@ dispatch(Notifications.warning(notification));
165165
dispatch(Notifications.info(notification));
166166
dispatch(Notifications.hide(uid)); // Hides notification based on uid
167167
dispatch(Notifications.removeAll()); // Removes all notifications
168+
169+
// OR //
170+
171+
import { show, success, error, warning, info, hide, removeAll } from 'react-notification-system-redux';
172+
173+
dispatch(show(notification, level));
174+
dispatch(success(notification));
175+
dispatch(error(notification));
176+
dispatch(warning(notification));
177+
dispatch(info(notification));
178+
dispatch(hide(uid)); // Hides notification based on uid
179+
dispatch(removeAll()); // Removes all notifications
168180
```
169181

170182

example/src/components/container.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import {connect} from 'react-redux';
44
import ReactDOM from 'react-dom';
55

6-
import Notifications from 'react-notification-system-redux';
6+
import Notifications, { success, error, warning, info, removeAll } from 'react-notification-system-redux';
77

88
const notificationOpts = {
99
// uid: 'once-please', // you can specify your own uid if required
@@ -33,14 +33,14 @@ class Container extends React.Component {
3333
}
3434

3535
handleClick() {
36-
this.dispatchNotification(Notifications.success, 250);
37-
this.dispatchNotification(Notifications.error, 500);
38-
this.dispatchNotification(Notifications.warning, 750);
39-
this.dispatchNotification(Notifications.info, 1000);
36+
this.dispatchNotification(success, 250);
37+
this.dispatchNotification(error, 500);
38+
this.dispatchNotification(warning, 750);
39+
this.dispatchNotification(info, 1000);
4040
}
4141

4242
handleRemoveAll() {
43-
this.context.store.dispatch(Notifications.removeAll());
43+
this.context.store.dispatch(removeAll());
4444
}
4545

4646
render() {

test/__tests__/notifications.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { mount } from 'enzyme';
33
import { expect } from 'chai';
44
import { jsdom } from 'jsdom';
55
import sinon from 'sinon';
6-
import Component from '../../src/notifications';
6+
import Component, { show, success, error, warning, info, hide, removeAll } from '../../src/notifications';
77
import NotifySystem from 'react-notification-system';
88

99
const createDOM = () => jsdom('<!doctype html><html><body><div></div></body></html>');
@@ -36,7 +36,17 @@ describe('NotificationsComponent', () => {
3636

3737
beforeEach(() => {
3838
DOM = createDOM();
39-
});
39+
});
40+
41+
it('exports all actions', () => {
42+
expect(show).to.be.a('function');
43+
expect(success).to.be.a('function');
44+
expect(error).to.be.a('function');
45+
expect(warning).to.be.a('function');
46+
expect(info).to.be.a('function');
47+
expect(hide).to.be.a('function');
48+
expect(removeAll).to.be.a('function');
49+
});
4050

4151
it('should render one <NotifySystem /> component', () => {
4252
const wrapper = mountComponent();

0 commit comments

Comments
 (0)