@vroskus/library-history 1.0.3 → 1.0.5
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.
- package/package.json +6 -2
- package/.eslintrc +0 -77
- package/src/index.ts +0 -81
- package/tsconfig.json +0 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vroskus/library-history",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "History",
|
|
5
5
|
"author": "Vilius Roškus <vilius@regattas.eu>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
"url": "git+https://github.com/vroskus/library-history.git"
|
|
10
10
|
},
|
|
11
11
|
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/"
|
|
15
|
+
],
|
|
12
16
|
"scripts": {
|
|
13
17
|
"postinstall": "npm run build",
|
|
14
18
|
"build": "tsc",
|
|
@@ -17,7 +21,7 @@
|
|
|
17
21
|
"test:e2e": "echo 'No tests'"
|
|
18
22
|
},
|
|
19
23
|
"dependencies": {
|
|
20
|
-
"@vroskus/library-types": "1.0.
|
|
24
|
+
"@vroskus/library-types": "1.0.5",
|
|
21
25
|
"react": "18.2.0",
|
|
22
26
|
"react-router-dom": "5.3.0"
|
|
23
27
|
},
|
package/.eslintrc
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"parser": "@typescript-eslint/parser",
|
|
4
|
-
"parserOptions": {
|
|
5
|
-
"requireConfigFile": false,
|
|
6
|
-
"project": ["tsconfig.json"]
|
|
7
|
-
},
|
|
8
|
-
"extends": [
|
|
9
|
-
"airbnb-base",
|
|
10
|
-
"airbnb-typescript",
|
|
11
|
-
"plugin:import/recommended",
|
|
12
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
13
|
-
"plugin:@typescript-eslint/recommended",
|
|
14
|
-
"plugin:sort/recommended"
|
|
15
|
-
],
|
|
16
|
-
"plugins": [
|
|
17
|
-
"@typescript-eslint",
|
|
18
|
-
"import",
|
|
19
|
-
"import-newlines",
|
|
20
|
-
"react",
|
|
21
|
-
"sort"
|
|
22
|
-
],
|
|
23
|
-
"rules": {
|
|
24
|
-
"complexity": ["error", 5],
|
|
25
|
-
"@typescript-eslint/ban-ts-comment": [1],
|
|
26
|
-
"@typescript-eslint/no-unused-vars": [2],
|
|
27
|
-
"curly": ["error", "all"],
|
|
28
|
-
"import/no-cycle": [0],
|
|
29
|
-
"no-await-in-loop": 0,
|
|
30
|
-
"no-console": "error",
|
|
31
|
-
"no-duplicate-imports": [0],
|
|
32
|
-
"no-loss-of-precision": [0],
|
|
33
|
-
"no-restricted-syntax": 0,
|
|
34
|
-
"no-unreachable-loop": [0],
|
|
35
|
-
"no-useless-backreference": [0],
|
|
36
|
-
"no-unused-private-class-members": [2],
|
|
37
|
-
"padding-line-between-statements": ["error", {
|
|
38
|
-
"blankLine": "always",
|
|
39
|
-
"prev": ["const", "let"],
|
|
40
|
-
"next": "*"
|
|
41
|
-
}, {
|
|
42
|
-
"blankLine": "any",
|
|
43
|
-
"prev": ["const", "let"],
|
|
44
|
-
"next": ["const", "let"]
|
|
45
|
-
}, {
|
|
46
|
-
"blankLine": "always",
|
|
47
|
-
"prev": ["if", "function", "for"],
|
|
48
|
-
"next": "*"
|
|
49
|
-
}, {
|
|
50
|
-
"blankLine": "always",
|
|
51
|
-
"prev": "*",
|
|
52
|
-
"next": "return"
|
|
53
|
-
}],
|
|
54
|
-
"object-curly-newline": ["error", {
|
|
55
|
-
"ObjectExpression": "always",
|
|
56
|
-
"ObjectPattern": "always",
|
|
57
|
-
"ImportDeclaration": "always",
|
|
58
|
-
"ExportDeclaration": "always"
|
|
59
|
-
}],
|
|
60
|
-
"function-call-argument-newline": ["error", "always"],
|
|
61
|
-
"object-property-newline": ["error", {
|
|
62
|
-
"allowMultiplePropertiesPerLine": false
|
|
63
|
-
}],
|
|
64
|
-
"import-newlines/enforce": ["error", {
|
|
65
|
-
"items": 1,
|
|
66
|
-
"forceSingleLine": false
|
|
67
|
-
}],
|
|
68
|
-
"sort/imports": [0],
|
|
69
|
-
"sort/exports": [0]
|
|
70
|
-
},
|
|
71
|
-
"env": {
|
|
72
|
-
"browser": true,
|
|
73
|
-
"node": true,
|
|
74
|
-
"jest": true,
|
|
75
|
-
"es6": true
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/* eslint-disable class-methods-use-this */
|
|
2
|
-
// Global Types
|
|
3
|
-
import type {
|
|
4
|
-
$Location,
|
|
5
|
-
$WebRouter,
|
|
6
|
-
} from '@vroskus/library-types';
|
|
7
|
-
|
|
8
|
-
import * as React from 'react';
|
|
9
|
-
import {
|
|
10
|
-
withRouter,
|
|
11
|
-
} from 'react-router-dom';
|
|
12
|
-
|
|
13
|
-
// Types
|
|
14
|
-
type $Listener = (location: $Location) => unknown;
|
|
15
|
-
|
|
16
|
-
type $Props = $WebRouter;
|
|
17
|
-
|
|
18
|
-
let globalHistory = null;
|
|
19
|
-
const listeners: Array<$Listener> = [];
|
|
20
|
-
|
|
21
|
-
class Spy extends React.Component<$Props> {
|
|
22
|
-
componentDidMount(): void {
|
|
23
|
-
this.trackHistoryChange();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
componentDidUpdate(): void {
|
|
27
|
-
this.trackHistoryChange();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
trackHistoryChange(): void {
|
|
31
|
-
const {
|
|
32
|
-
history,
|
|
33
|
-
} = this.props;
|
|
34
|
-
|
|
35
|
-
listeners.forEach((listener: $Listener) => {
|
|
36
|
-
listener(history.location);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
globalHistory = history;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
render(): null {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type $RedirectParams = {
|
|
48
|
-
hash?: string;
|
|
49
|
-
pathname?: string;
|
|
50
|
-
search?: string;
|
|
51
|
-
state?: object;
|
|
52
|
-
};
|
|
53
|
-
export type $RedirectResponse = $RedirectParams;
|
|
54
|
-
|
|
55
|
-
export type $HistoryService = {
|
|
56
|
-
readonly addListener: (listener: $Listener) => number;
|
|
57
|
-
readonly getCurrentPathname: () => string | null;
|
|
58
|
-
readonly redirect: (arg0: $RedirectParams) => $RedirectResponse;
|
|
59
|
-
readonly render: unknown;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const HistoryService: $HistoryService = {
|
|
63
|
-
addListener: (listener: $Listener) => listeners.push(listener),
|
|
64
|
-
getCurrentPathname: () => {
|
|
65
|
-
if (window && window.location) {
|
|
66
|
-
return window.location.pathname || null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return null;
|
|
70
|
-
},
|
|
71
|
-
redirect: (params: $RedirectParams): $RedirectResponse => {
|
|
72
|
-
if (globalHistory) {
|
|
73
|
-
globalHistory.push(params);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return params;
|
|
77
|
-
},
|
|
78
|
-
render: withRouter(Spy) as unknown,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export default HistoryService;
|
package/tsconfig.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"outDir": "./dist/",
|
|
4
|
-
"types": ["node", "jest"],
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"noImplicitAny": false,
|
|
9
|
-
"removeComments": true,
|
|
10
|
-
"noLib": false,
|
|
11
|
-
"emitDecoratorMetadata": true,
|
|
12
|
-
"experimentalDecorators": true,
|
|
13
|
-
"target": "es6",
|
|
14
|
-
"sourceMap": true,
|
|
15
|
-
"lib": [
|
|
16
|
-
"dom",
|
|
17
|
-
"es6"
|
|
18
|
-
],
|
|
19
|
-
"jsx": "react"
|
|
20
|
-
},
|
|
21
|
-
"exclude": [
|
|
22
|
-
"node_modules",
|
|
23
|
-
"./dist/**/*"
|
|
24
|
-
],
|
|
25
|
-
"include": [
|
|
26
|
-
"./src"
|
|
27
|
-
]
|
|
28
|
-
}
|