
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
store2state-dom
Advanced tools
An extension of the `store2state` library that provides a straightforward way to bind application state changes to DOM elements in vanilla JavaScript
The Store2State DOM Subscriber is an extension of the store2state
library that provides a straightforward way to bind application state changes to DOM elements in vanilla JavaScript. This utility allows you to manage UI updates efficiently by subscribing to state changes and reacting accordingly.
Ensure store2state
is installed in your project:
# Install store2state if not already installed
npm install store2state
Install store2state-dom
package in your project:
npm install store2state-dom
Begin by creating a store with an initial state using store2state
:
import { createStore } from 'store2state';
const initialState = {
count: 0,
message: 'Hello, World!',
};
const store = createStore(initialState);
Use the createSubscriber
function to create a new subscriber for a DOM element:
import { createSubscriber } from './path-to-subscriber-file';
const displayElement = document.getElementById('display');
const subscriber = createSubscriber(store, displayElement);
Add actions to be executed when the state changes:
subscriber.addSubscriber((ele, state) => {
ele.textContent = `Count: ${state.count}, Message: ${state.message}`;
}).subscribe();
Initialize the DOM element with the current state:
subscriber.init((ele, state) => {
ele.textContent = `Initial Count: ${state.count}, Message: ${state.message}`;
});
Add event listeners to DOM elements:
const incrementButton = document.getElementById('increment');
subscriber.addEventListener('click', (event, store) => {
store.set((state) => ({ count: state.count + 1 }));
});
Execute custom actions and dispatch events to update subscribers:
subscriber.action((store) => {
// Perform any state updates or other logic here
store.set((state) => ({ message: 'State Updated!' }));
});
CreateSubscriber
MethodsaddSubscriber(action: Action<State>)
: Adds an action to be executed on state changes. Returns the CreateSubscriber
instance for method chaining.getLastSubscriberId()
: Returns the ID of the last added subscriber.removeSubscriber(id: string)
: Removes a subscriber action by ID. Returns the CreateSubscriber
instance.addEventListener(eventName: string, listener: (event: Event, store: Store<State>) => void)
: Adds an event listener to the DOM element, automatically executing the provided listener in response to events. Returns the CreateSubscriber
instance.subscribe()
: Subscribes all added actions to state changes. Returns the CreateSubscriber
instance.init(initAction: Action<State>)
: Initializes the DOM element with the current state. Returns the CreateSubscriber
instance.action(actionMethod: (store: Store<State>) => void)
: Executes a custom action and dispatches a domChange
event to update subscribers.Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
An extension of the `store2state` library that provides a straightforward way to bind application state changes to DOM elements in vanilla JavaScript
The npm package store2state-dom receives a total of 0 weekly downloads. As such, store2state-dom popularity was classified as not popular.
We found that store2state-dom demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.