https://github.com/fongandrew/react-sub-dispatch
WIP
https://github.com/fongandrew/react-sub-dispatch
Last synced: 3 months ago
JSON representation
WIP
- Host: GitHub
- URL: https://github.com/fongandrew/react-sub-dispatch
- Owner: fongandrew
- License: mit
- Created: 2017-12-18T01:39:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-18T01:40:20.000Z (over 7 years ago)
- Last Synced: 2025-02-21T08:51:25.598Z (3 months ago)
- Language: TypeScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# react-sub-dispatch
[](https://travis-ci.org/fongandrew/react-sub-dispatch)A datastore-agnostic library for subscribing React components to a data source
and dispatching events. Inspired by `react-redux`, but comes with a more
generic interface for connecting stores.```ts
connect(
(context, ownProps) => ({
prop1: [Sub1, { store: context.store, key1: props.key1 }],
prop2: [Sub2, { store: context.store, key2: props.key2 }]
}),(context, dispatch, ownProps) => ({
}),
(context, subProps, dispatchProps, ownProps) => ({
})
);connect(
(ownProps, context) => ({
prop1: [Sub1, { key1: props.key1 }, context],
prop2: [Sub2, { key2: props.key2 }, context]
}),(dispatch, ownProps, context) => ({
}),
(subProps, dispatchProps, ownProps, context) => ({
...subProps,
...dispatchProps
})
)```
Could just use React context above.
Or could use alt context set by provider ...```tsx
```
```ts
connect((ownProps, services, dispatch) => ({
...subscribe({
data1: subscribeToX(props),
data2: subscribeToY(props)
}),
onClick: () => dispatch({ type: 'INCR', value: 123 }),
otherProp: ownProps.value
}));
```