
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
mobx-fog-of-war
Advanced tools
A simple, lazy front-end request coordinator and cache for React and mobx. Load your data by simply trying to view it, and build up a picture of your server's data over time.
A simple, lazy front-end request coordinator and cache for React and mobx. Load your data by simply trying to view it, and build up a picture of your server's data over time.
You're not required to think about "requesting" data in advance. Just try to access it using store.get() or the store.useGet() React hook, and if the corresponding data in your cache is missing or stale it'll prompt your request function to go and load the data. This makes it easy to do your data joins on the front-end, right in your components, keeping your data-joining-logic as minimal as possible.
When used with buffering and batching, it could be thought of as "dataloader but for React".
If your server is performing data joins (as many graphql APIs tend to do) then mobx-fog-of-war
may not be right for you. In this case check out enty for normalised state management.
yarn add react mobx mobx-react mobx-fog-of-war
// or
npm install --save react mobx mobx-react mobx-fog-of-war
Store
+ asyncRequest
< 2.1KB gzipped, entire library < 3KB gzipped// requesters
const getUser = async (id: UserArgs): Promise<User> => {
const response = await fetch(`http://example.com/user/${id}`)
return new User(await response.json());
};
const getPet = async (id: PetArgs): Promise<Pet> => {
const response = await fetch(`http://example.com/pet/${id}`)
return new Pet(await response.json());
};
// stores
import {Store, asyncRequest} from 'mobx-fog-of-war';
const userStore = new Store<string,User,Error>({
name: 'User Store',
staleTime: 60, // after 60 seconds, the item is eligible to be requested again
request: asyncRequest(getUser)
});
const petStore = new Store<string,Pet,Error>({
name: 'Pet Store',
staleTime: 60,
request: asyncRequest(getPet)
});
import {observer} from 'mobx-react';
// render a user, it'll go get the required data
const UserView = observer(props => {
const userFromStore = userStore.useGet(props.userId);
return <Loader storeItem={userFromStore}>
{user => <div>
Name: {user.name}
Pets: {user.petIds.map(petId => <PetView key={petId} petId={petId} />)}
</div>}
</Loader>;
});
// render some pets, they'll go get the required data
const PetView = observer(props => {
const petFromStore = petStore.useGet(props.petId);
return <Loader storeItem={petFromStore}>
{pet => <div>
Pet name: {pet.name}
</div>}
</Loader>;
});
// handle request state as you like
// for example, a component using render props
// or use the in-built <Load> component
const Loader = observer(props => {
let {storeItem, children} = props;
if(storeItem.loading) return <div>Loading</div>;
if(storeItem.hasError) return <div>Error: {storeItem.error.message}</div>;
if(!storeItem.hasData) return null;
return children(storeItem.data);
});
This library is written and maintained by Damien Clarke, with feedback from others at 92green. It was built to meet the data-requesting and caching needs of products at Blueflag. All online library discussion happens over on Github.
I hope this library helps solve some data requesting problems for you. 🎉
FAQs
A simple, lazy front-end request coordinator and cache for React and mobx. Load your data by simply trying to view it, and build up a picture of your server's data over time.
The npm package mobx-fog-of-war receives a total of 29 weekly downloads. As such, mobx-fog-of-war popularity was classified as not popular.
We found that mobx-fog-of-war 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
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.