Skip to content

Commit 0760efc

Browse files
committed
Remove unnecessary reduxify() annotation and replace with connect()
1 parent 9f022dc commit 0760efc

35 files changed

+83
-166
lines changed

README.md

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,23 +1466,13 @@ and add the option manually:
14661466
```
14671467
14681468
When enabled this lets you create and use decorators that despite being simple functions provide an easy way
1469-
to compose behavior, dramatically reduce repetitive boilerplate and improve readability as seen with the
1470-
[@reduxify()](https://github.com/ServiceStackApps/typescript-redux/blob/661f9fcc1ce6c4a7b66064ce3511033d37a26d99/src/TypeScriptRedux/src/example08/core.ts#L18)
1471-
decorator which just delegates to Redux connect():
1469+
to compose behavior, dramatically reduce repetitive boilerplate and improve readability where we're able to
1470+
get the ideal declarative API we want for defining Redux-connected Components in a single cohesive unit,
1471+
with property mapping functions declared above the class declaration and all interim artifacts abstracted away
1472+
by using Redux's `connect()` as a decorator instead:
14721473
14731474
```typescript
1474-
export function reduxify(mapStateToProps?: MapStateToProps,
1475-
mapDispatchToProps?: MapDispatchToPropsFunction | MapDispatchToPropsObject) {
1476-
return target => connect(mapStateToProps, mapDispatchToProps)(target);
1477-
}
1478-
```
1479-
1480-
With just this simple change we get the ideal declarative API we want for defining Redux-connected Components
1481-
which are now defined in a single unit, with property mapping functions declared above the class declaration
1482-
and all interim artifacts abstracted away:
1483-
1484-
```typescript
1485-
@reduxify(
1475+
@connect(
14861476
(state) => ({ color: state.color }),
14871477
(dispatch) => ({ setColor: (color) => dispatch({ type: 'COLOR_CHANGE', color }) })
14881478
)
@@ -1722,8 +1712,6 @@ Surprisingly most of the code to make this happen is encapsulated within the Rea
17221712
/// <reference path='../../typings/browser.d.ts'/>
17231713

17241714
import * as React from 'react';
1725-
import { connect } from 'react-redux';
1726-
import { reduxify } from './core';
17271715
import 'jquery';
17281716
import 'ss-utils';
17291717

@@ -1737,12 +1725,12 @@ export default class Connect extends React.Component<any, any> {
17371725
channels: ["home"], currentUser: null, users: [],
17381726
connectedToUserId: null, connectedUserActions: [], connectedStateIndex: -1
17391727
};
1740-
var source = new EventSource(serverEventsUrl());
1728+
var source = new EventSource("/event-stream?channels=home");
17411729
$(source).handleServerEvents({
17421730
handlers: {
17431731
onConnect: (currentUser) => {
17441732
currentUser.usersChannel = userChannel(currentUser.userId);
1745-
this.setState({currentUser, users: filterUsers(this.state.users,currentUser.userId)});
1733+
this.setState({ currentUser, users: filterUsers(this.state.users, currentUser.userId) });
17461734
this.props.onConnect(currentUser);
17471735
},
17481736
onJoin: () => this.refreshUsers(),
@@ -1757,8 +1745,9 @@ export default class Connect extends React.Component<any, any> {
17571745
$.ss.postJSON(`/send-user/${o.replyTo}?selector=cmd.onState`, state);
17581746
},
17591747
onState: (json, e) => {
1760-
this.props.store.dispatch({
1761-
type:'LOAD', state:json ? JSON.parse(json) : this.props.defaultState });
1748+
this.props.store.dispatch({
1749+
type: 'LOAD', state: json ? JSON.parse(json) : this.props.defaultState
1750+
});
17621751
},
17631752
publishAction: (json, e) => {
17641753
var action = JSON.parse(json);

src/TypeScriptRedux/app.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TypeScriptRedux/app.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TypeScriptRedux/src/example08/Counter.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TypeScriptRedux/src/example08/Counter.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TypeScriptRedux/src/example08/Counter.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import * as React from 'react';
44
import { connect } from 'react-redux';
5-
import { reduxify } from './core';
65

76
interface IHelloWorldProps {
87
field: string;
@@ -12,7 +11,7 @@ interface IHelloWorldProps {
1211
decr?: Function;
1312
}
1413

15-
@reduxify(
14+
@connect(
1615
(state, props) => ({ counter: (state[props.field] || 0) }),
1716
(dispatch) => ({
1817
incr: (field, step) => {

src/TypeScriptRedux/src/example08/ShapeMaker.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TypeScriptRedux/src/example08/ShapeMaker.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TypeScriptRedux/src/example08/ShapeMaker.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import * as React from 'react';
44
import { connect } from 'react-redux';
55
import { isDark } from './ColorPicker';
6-
import { reduxify } from './core';
76

8-
@reduxify(
7+
@connect(
98
(state) => ({
109
width: state.width, height: state.height, color: state.color,
1110
top: state.nextShapeId * 10, left: state.nextShapeId * 10

src/TypeScriptRedux/src/example08/ShapeViewer.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)