
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
resource-toolkit
Advanced tools
Async and RESTful resource management tool.
Often we consume RESTful APIs, like for a CRUD, using reactive UIs (with React or not). And there are a few state scenarios always present and our UI demands some questions to be answered:
filter
when you remove elements for your data?map
for editing?While this is not a UI lib, it's a state helper to automate all of these state changes above. It's type safed, has high test coverage (written with TDD). Your code commits using this for repetitive CRUDs will be short, readable, safer by pure automation. You'll be free to focus on crafting other complex designed behaviours.
This lib is a composition mostly pure functions (based on Reducer pattern), so It's also supposed to be easily integrated on any state manager you're using, like Redux, MobX or just raw React Hooks (or even class-based life cycle methods).
npm install --save resource-toolkit
You may already see a running To Do List application here, crafted for didactic reasons with a friend: https://github.com/Mazuh/octo-todo (warning: it is currently using an old version unstable version)
Here are a few dumb examples in React.
import React from "react";
import { makeReducerAssets } from 'resource-toolkit';
const usersResource = makeReducerAssets({
name: 'user',
idKey: 'userId',
gateway: {
fetchMany: async (ids = null, ...args) => {
return [
{ userId: 42, name: 'Marcell' },
{ userId: 11, name: 'David' },
{ userId: 22, name: 'Rodrigo' },
];
},
},
});
export default function App() {
const [users, dispatch] = React.useReducer(usersResource.reducer, usersResource.initialState);
React.useEffect(() => {
usersResource.actions.readAll()(dispatch);
}, [dispatch]);
if (users.isLoading) {
return <p>Doing something...</p>;
}
if (users.items.length === 0) {
return <p>No users found.</p>;
}
return (
<div>
<ul>
{users.items.map(user => (
<li key={user.userId}>{user.name}</li>
))}
</ul>
</div>
);
}
Check it out on CodeSandbox: https://codesandbox.io/s/resource-toolkit-usage-7h9td?fontsize=14&hidenavigation=1&theme=dark
Feel free to fork it and test the features by yourself.
Please consult CONTIRBUTING for guidelines on contributing to this project.
FAQs
Async and RESTful resource management tool.
We found that resource-toolkit 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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.