
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
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
We found that store2state-dom demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.