Skip to content

Commit

Permalink
Notices: Extract default status to constant
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Nov 7, 2018
1 parent 18407d6 commit d653835
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/notices/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isPlainObject, uniqueId } from 'lodash';
/**
* Internal dependencies
*/
import { DEFAULT_CONTEXT } from './constants';
import { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';

/**
* Yields action objects used in signalling that a notice is to be created.
Expand All @@ -27,13 +27,13 @@ import { DEFAULT_CONTEXT } from './constants';
* @param {?Array<WPNoticeAction>} options.actions User actions to be
* presented with notice.
*/
export function* createNotice( statusOrNotice = 'info', content, options = {} ) {
export function* createNotice( statusOrNotice = DEFAULT_STATUS, content, options = {} ) {
let status;

if ( isPlainObject( statusOrNotice ) ) {
// Support overloaded form `createNotice( notice: WPNotice )`.
options = statusOrNotice;
( { status = 'info', content } = options );
( { status = DEFAULT_STATUS, content } = options );
} else {
// Else consider the first argument the status type string.
status = statusOrNotice;
Expand Down
7 changes: 7 additions & 0 deletions packages/notices/src/store/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@
* @type {string}
*/
export const DEFAULT_CONTEXT = 'global';

/**
* Default notice status.
*
* @type {string}
*/
export const DEFAULT_STATUS = 'info';
6 changes: 3 additions & 3 deletions packages/notices/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
createWarningNotice,
removeNotice,
} from '../actions';
import { DEFAULT_CONTEXT } from '../constants';
import { DEFAULT_CONTEXT, DEFAULT_STATUS } from '../constants';

describe( 'actions', () => {
describe( 'createNotice', () => {
Expand Down Expand Up @@ -83,7 +83,7 @@ describe( 'actions', () => {
context: DEFAULT_CONTEXT,
notice: {
id,
status: 'info',
status: DEFAULT_STATUS,
content,
isDismissible: false,
actions: [],
Expand Down Expand Up @@ -131,7 +131,7 @@ describe( 'actions', () => {
type: 'CREATE_NOTICE',
context: DEFAULT_CONTEXT,
notice: {
status: 'info',
status: DEFAULT_STATUS,
content,
isDismissible: true,
id: expect.any( String ),
Expand Down

0 comments on commit d653835

Please sign in to comment.