@vroskus/library-history 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +65 -0
  2. package/package.json +43 -0
package/dist/index.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const React = __importStar(require("react"));
27
+ const react_router_dom_1 = require("react-router-dom");
28
+ let globalHistory = null;
29
+ const listeners = [];
30
+ class Spy extends React.Component {
31
+ componentDidMount() {
32
+ this.trackHistoryChange();
33
+ }
34
+ componentDidUpdate() {
35
+ this.trackHistoryChange();
36
+ }
37
+ trackHistoryChange() {
38
+ const { history, } = this.props;
39
+ listeners.forEach((listener) => {
40
+ listener(history.location);
41
+ });
42
+ globalHistory = history;
43
+ }
44
+ render() {
45
+ return null;
46
+ }
47
+ }
48
+ const HistoryService = {
49
+ addListener: (listener) => listeners.push(listener),
50
+ getCurrentPathname: () => {
51
+ if (window && window.location) {
52
+ return window.location.pathname || null;
53
+ }
54
+ return null;
55
+ },
56
+ redirect: (params) => {
57
+ if (globalHistory) {
58
+ globalHistory.push(params);
59
+ }
60
+ return params;
61
+ },
62
+ render: (0, react_router_dom_1.withRouter)(Spy),
63
+ };
64
+ exports.default = HistoryService;
65
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@vroskus/library-history",
3
+ "version": "1.0.0",
4
+ "description": "History",
5
+ "author": "Vilius Roškus <vilius@regattas.eu>",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/vroskus/library-history.git"
10
+ },
11
+ "main": "dist/index.js",
12
+ "files": [
13
+ "dist/index.js"
14
+ ],
15
+ "scripts": {
16
+ "postinstall": "npm run build",
17
+ "build": "tsc",
18
+ "test": "npm run test:eslint && npm run test:e2e",
19
+ "test:eslint": "eslint src --fix",
20
+ "test:e2e": "echo 'No tests'"
21
+ },
22
+ "dependencies": {
23
+ "@vroskus/library-types": "1.0.1",
24
+ "react": "18.2.0",
25
+ "react-router-dom": "5.3.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/jest": "29.5.0",
29
+ "@types/node": "18.15.11",
30
+ "@types/react": "18.0.33",
31
+ "@typescript-eslint/eslint-plugin": "5.53.0",
32
+ "@typescript-eslint/parser": "5.53.0",
33
+ "eslint": "8.34.0",
34
+ "eslint-config-airbnb-base": "15.0.0",
35
+ "eslint-config-airbnb-typescript": "17.0.0",
36
+ "eslint-plugin-import": "2.27.5",
37
+ "eslint-plugin-import-newlines": "1.3.1",
38
+ "eslint-plugin-react": "7.32.2",
39
+ "eslint-plugin-sort": "2.4.0",
40
+ "npm-check": "6.0.1",
41
+ "typescript": "4.9.5"
42
+ }
43
+ }