Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
redux-saga-resources
Advanced tools
Module under development
Install
npm install --save redux-saga-resources redux-saga-rest
Configuration
import { API, defaultMiddleware } from 'redux-saga-rest';
import { createResource, createEditor, httpMiddleware } from 'redux-saga-resources';
const api = new API('/api')
.use(defaultMiddleware());
export const resource = createResource('post', api, httpMiddleware('/posts', api));
export const editor = createEditor(resource);
Implementation
import { createStore, combineReducers, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga';
const saga = createSagaMiddleware();
const store = createStore(
combineReducers({
postResource: resource.reducer,
postEditor: editor.reducer
}),
null,
applyMiddleware(
saga
)
);
saga.run(resource.saga);
Examples
store.dispatch(resource.creators.doList());
store.dispatch(resource.creators.doCreate(resource.create({ title: 'New Post' })));
store.dispatch(editor.creators.doCreate({ title: 'New Post' }));
List of items
@connect(
(state) => ({
items: resource.selectors.items(state)
}),
(dispatch) => ({
create: () => dispatch(editor.creators.doCreate({ title: 'New Post' })),
edit: (item) => dispatch(editor.creators.doEdit(item))
})
)
class App extends Component {
render() {
return (
<div>
<button type="button" onClick={() => this.props.create()}>New Post</button>
{this.props.items.map(post => (
<div class="item">
{post.title}
<button type="button" onClick={() => this.props.edit(post)}>edit</button>
</div>
))}
</div>
)
}
}
Edit single item
@connect(
(state) => ({
item: editor.selectors.item(state),
unmodified: resource.fields.isUnmodified(editor.selectors.item(state)),
neverCommited: resource.fields.neverCommited(editor.selectors.item(state))
}),
(dispatch) => ({
create: () => dispatch(editor.creators.doCreate({ title: 'New Post' })),
edit: (item) => dispatch(editor.creators.doEdit(item)),
reload: (item) => dispatch(editor.creators.doRead(item)),
save: (item) => dispatch(editor.creators.doUpdate(item)),
remove: (item) => dispatch(editor.creators.doDelete(item))
})
)
class BlogPost extends Component {
render() {
return (
<form>
<input placeholder="Title" value={this.props.item.title} onChange={(e) => this.props.edit({ ...this.props.item, title: e.target.value })} />
<br/>
<button type="button" onClick={() => this.props.create()}>New</button>
<button type="button" onClick={() => this.props.reload()} disabled={this.props.neverCommited}>Reload</button>
<button type="button" onClick={() => this.props.remove()} disabled={this.props.neverCommited}>Delete</button>
<button type="button" onClick={() => this.props.save()} disabled={this.props.unmodified}>Save</button>
</form>
)
}
}
FAQs
See also [redux-saga-resources-example](https://github.com/Zaibot/redux-saga-resources-example)
The npm package redux-saga-resources receives a total of 5 weekly downloads. As such, redux-saga-resources popularity was classified as not popular.
We found that redux-saga-resources demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.