You've already forked redux-doctitle
Hello, redux-doctitle!
This commit is contained in:
8
src/actions.js
Normal file
8
src/actions.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import {TITLE_ACTIONS_SET} from "./defs";
|
||||
|
||||
export const setDocumentTitle = (title = "") => {
|
||||
return {
|
||||
type: TITLE_ACTIONS_SET,
|
||||
title: title
|
||||
};
|
||||
};
|
||||
1
src/defs.js
Normal file
1
src/defs.js
Normal file
@@ -0,0 +1 @@
|
||||
export const TITLE_ACTIONS_SET = "BTHLABS/REDUX_DOCTITLE_MW_TITLE_ACTIONS_SET";
|
||||
2
src/index.js
Normal file
2
src/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
export {setDocumentTitle} from "./actions";
|
||||
export {documentTitleMiddlewareFactory} from "./middleware";
|
||||
16
src/middleware.js
Normal file
16
src/middleware.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import {TITLE_ACTIONS_SET} from "./defs";
|
||||
|
||||
export const documentTitleMiddlewareFactory = (defaultTitleParts = []) => {
|
||||
return (store, getState) => next => action => {
|
||||
if (action.type == TITLE_ACTIONS_SET) {
|
||||
let titleParts = [].concat(defaultTitleParts);
|
||||
if (action.title) {
|
||||
titleParts.unshift(action.title);
|
||||
}
|
||||
|
||||
window.document.title = titleParts.join(" | ");
|
||||
} else {
|
||||
next(action);
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user