Hello, redux-doctitle!

This commit is contained in:
2018-01-18 17:53:52 +01:00
commit 64c18f7eba
17 changed files with 560 additions and 0 deletions

8
src/actions.js Normal file
View 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
View File

@@ -0,0 +1 @@
export const TITLE_ACTIONS_SET = "BTHLABS/REDUX_DOCTITLE_MW_TITLE_ACTIONS_SET";

2
src/index.js Normal file
View File

@@ -0,0 +1,2 @@
export {setDocumentTitle} from "./actions";
export {documentTitleMiddlewareFactory} from "./middleware";

16
src/middleware.js Normal file
View 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);
}
};
};