Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
easy-state
Advanced tools
Simple state manipulation without any frameworks.
First things first; import the module:
import createStateTree from 'easy-state';
To get you started, initialize a state tree with the function createStateTree
.
const store = createStateTree({
counter: 1,
});
To retrieve the current state at any point in time, use getState
:
store.getState();
To alter any state from your state tree, use setState
:
store.setState({
counter: 2
});
Keep your UI in sync with your state by using subscribe
:
store.subscribe((prevState, nextState) => {
DOMElement.innerHTML = nextState.counter;
});
For larger applications you can divide your stores into smaller pieces, to get more control over certain parts.
Counter-example:
const store = createStateTree({ counter: 0 });
const initEventListeners = () => {
myIncrementButton.addEventListener('click', handleIncrement);
myDecrementButton.addEventListener('click', handleDecrement);
};
const handleIncrement = () => {
const counter = store.getState().counter;
store.setState({ counter: counter + 1 });
}
const handleDecrement = () => {
const counter = store.getState().counter;
store.setState({ counter: counter - 1 });
}
const renderCounter = (counter) => {
myDOMCounterElement.innerHTML = counter;
}
initEventListeners();
renderCounter(store.getState().counter);
store.subscribe((prevState, nextState) => {
renderCounter(nextState.counter);
});
Install
$ git clone https://github.com/oyvindhermansen/easy-state.git
$ cd easy-state
$ yarn install
Run the demo whitch is powered by webpack and webpack dev-server.
The dev-server listens for changes in both demo/
and src/
, so you can write module implementation and testing it in the browser at the same time.
$ yarn dev
Unit testing
$ yarn test
$ yarn test:watch
Test coverage
$ yarn coverage
Prettier
# Targets src, demo and __tests__ folders.
$ yarn prettier
Build for production
$ yarn build
I've often come across projects that needed to use plain jquery or vanilla JavaScript instead of any frameworks e.g React or VueJS, and there is one thing I've missed: Possibilty to have application state in sync with my UI without any hassle.
The library is inspired by both React and Redux. It's sort of a Redux-lib, without the reducers, action-creators and dispatching actions, but instead changing state with setState()-method like they do in React.
FAQs
Simple state manipulation without any frameworks.
The npm package easy-state receives a total of 0 weekly downloads. As such, easy-state popularity was classified as not popular.
We found that easy-state 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.