Skip to content

Commit

Permalink
Chore/action exports (#41)
Browse files Browse the repository at this point in the history
* Add .vscode to gitignore

* Add test for action exports

* Add action imports to example

* Add action import examples to readme
  • Loading branch information
gor181 committed Jul 18, 2017
1 parent 1103df6 commit f2722b6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ example/dist
*.sublime-*
.idea/
*.DS_Store
.vscode
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Dispatch notification actions from any other component:
import React, {PropTypes} from 'react';
import ReactDOM from 'react-dom';

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

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

handleClick() {
this.context.store.dispatch(
Notifications.success(notificationOpts)
success(notificationOpts)
);
}

Expand Down Expand Up @@ -165,6 +165,18 @@ dispatch(Notifications.warning(notification));
dispatch(Notifications.info(notification));
dispatch(Notifications.hide(uid)); // Hides notification based on uid
dispatch(Notifications.removeAll()); // Removes all notifications

// OR //

import { show, success, error, warning, info, hide, removeAll } from 'react-notification-system-redux';

dispatch(show(notification, level));
dispatch(success(notification));
dispatch(error(notification));
dispatch(warning(notification));
dispatch(info(notification));
dispatch(hide(uid)); // Hides notification based on uid
dispatch(removeAll()); // Removes all notifications
```


Expand Down
12 changes: 6 additions & 6 deletions example/src/components/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import {connect} from 'react-redux';
import ReactDOM from 'react-dom';

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

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

handleClick() {
this.dispatchNotification(Notifications.success, 250);
this.dispatchNotification(Notifications.error, 500);
this.dispatchNotification(Notifications.warning, 750);
this.dispatchNotification(Notifications.info, 1000);
this.dispatchNotification(success, 250);
this.dispatchNotification(error, 500);
this.dispatchNotification(warning, 750);
this.dispatchNotification(info, 1000);
}

handleRemoveAll() {
this.context.store.dispatch(Notifications.removeAll());
this.context.store.dispatch(removeAll());
}

render() {
Expand Down
14 changes: 12 additions & 2 deletions test/__tests__/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mount } from 'enzyme';
import { expect } from 'chai';
import { jsdom } from 'jsdom';
import sinon from 'sinon';
import Component from '../../src/notifications';
import Component, { show, success, error, warning, info, hide, removeAll } from '../../src/notifications';
import NotifySystem from 'react-notification-system';

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

beforeEach(() => {
DOM = createDOM();
});
});

it('exports all actions', () => {
expect(show).to.be.a('function');
expect(success).to.be.a('function');
expect(error).to.be.a('function');
expect(warning).to.be.a('function');
expect(info).to.be.a('function');
expect(hide).to.be.a('function');
expect(removeAll).to.be.a('function');
});

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

0 comments on commit f2722b6

Please sign in to comment.