Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@alwatr/context
Advanced tools
A simple yet powerful TypeScript library for managing application context and facilitating efficient communication between components.
A simple yet powerful TypeScript library for managing application context and facilitating efficient communication between components.
untilChange()
enables components to wait for context updates.npm install @alwatr/context
import {AlwatrContext} from '@alwatr/context';
// Create a new context
const userContext = new AlwatrContext<{name: string; email: string}>({name: 'user-context'});
// Set the context value
userContext.setValue({name: 'Alice', email: '[email address removed]'});
// Get the current context value
const currentUser = userContext.getValue();
console.log('Current user:', currentUser); // {name: 'Alice', email: '[email address removed]'}
// Subscribe to context changes
const subscription = userContext.subscribe((newUser) => {
console.log('User context updated:', newUser);
});
// Update the context
userContext.setValue({name: 'Bob', email: '[email address removed]'});
// Wait for the next context change asynchronously
const nextUser = await userContext.untilChange();
console.log('Next user:', nextUser);
// Unsubscribe when done
subscription.unsubscribe();
// Clear the context value
userContext.expire();
AlwatrContext
constructor(config: {name: string; loggerPrefix?: string})
: Creates a new AlwatrContext
instance.
config.name
: The name of the context (used for logging).config.loggerPrefix
: Optional prefix for log messages.getValue(): T | undefined
: Gets the current context value. Returns undefined
if the context has not been set or has expired.
setValue(value: T)
: Sets the context value and notifies all subscribers.
subscribe(listenerCallback: ListenerCallback<this, T>, options: SubscribeOptions = {}): SubscribeResult
: (Inherited from AlwatrObservable
) Subscribes to context changes.
listenerCallback
: The function to be called when the context value changes.options
:
once
: If true
, the listener will be automatically unsubscribed after the first change.priority
: If true
, the listener will be executed before other listeners.receivePrevious
: If true
, the listener will be immediately called with the current context value (if available).disabled
: If true
, the listener will not be executed.unsubscribe(listenerCallback: ListenerCallback<this, T>)
: (Inherited from AlwatrObservable
) Unsubscribes a listener from context changes.
expire()
: Clears the current context value without notifying subscribers.
untilChange()
: Returns a Promise that resolves with the next context value after a change occurs.
The following companies, organizations, and individuals support flux ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.
Contributions are welcome! Please read our contribution guidelines before submitting a pull request.
This project is licensed under the AGPL-3.0 License.
4.0.0 (2024-11-06)
actionRecord_
changedFAQs
A simple yet powerful TypeScript library for managing application context and facilitating efficient communication between components.
The npm package @alwatr/context receives a total of 239 weekly downloads. As such, @alwatr/context popularity was classified as not popular.
We found that @alwatr/context 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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.