git.fiddlerwoaroof.com
Browse code

Fix action-link

Ed Langley authored on 08/06/2019 20:19:53
Showing 2 changed files
... ...
@@ -14,9 +14,9 @@
14 14
   "version": "1.0.4",
15 15
   "license": "MIT",
16 16
   "peerDependencies": {
17
-    "redux": "^4.0.0",
18
-    "react": "^16.5.2",
17
+    "react": "^16.8.2",
19 18
     "react-dom": "^16.8.6",
19
+    "react-redux": "^7.0.3",
20 20
     "redux": "^4.0.0"
21 21
   },
22 22
   "dependencies": {
... ...
@@ -1,28 +1,33 @@
1
-const ActionLink = (React, PropTypes) => {
2
-  function ActionLink({ action, children, ...props }, { store }) {
3
-    const renderedRoute = store.pathForAction(action);
1
+const ActionLink = (React, PropTypes, ReactRedux) => {
2
+  class ActionLink extends React.Component {
3
+    constructor(props) {
4
+      super(props);
5
+    }
6
+    render() {
7
+      const { action, children, ...props } = this.props;
8
+      const { store } = this.context;
9
+      const renderedRoute = store.pathForAction(action);
4 10
 
5
-    return (
6
-      <a
7
-        href={renderedRoute}
8
-        onClick={ev => {
9
-          ev.preventDefault();
10
-          store.dispatch(action);
11
-        }}
12
-        {...props}
13
-      >
14
-        {children}
15
-      </a>
16
-    );
11
+      return (
12
+        <a
13
+          href={renderedRoute}
14
+          onClick={ev => {
15
+            ev.preventDefault();
16
+            store.dispatch(action);
17
+          }}
18
+          {...props}
19
+        >
20
+          {children}
21
+        </a>
22
+      );
23
+    }
17 24
   }
18 25
 
19 26
   ActionLink.propTypes = {
20
-    action: PropTypes.string,
27
+    action: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
21 28
     children: PropTypes.node
22 29
   };
23
-  ActionLink.contextTypes = {
24
-    store: PropTypes.object
25
-  };
30
+  ActionLink.contextType = ReactRedux.ReactReduxContext;
26 31
 
27 32
   return ActionLink;
28 33
 };
... ...
@@ -31,7 +36,9 @@ let OutComponent = ActionLink;
31 36
 try {
32 37
   const React = require("react");
33 38
   const PropTypes = require("prop-types");
34
-  OutComponent = ActionLink(React, PropTypes);
39
+  const ReactRedux = require("react-redux");
40
+
41
+  OutComponent = ActionLink(React, PropTypes, ReactRedux);
35 42
 } catch (e) {
36 43
   /* empty */
37 44
 }