Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
EchoProp is a lightweight library that enables reactive properties on JavaScript objects using RxJS ReplaySubject
. It allows you to track and observe property changes with options for validation and configurable replay counts, making state management in reactive programming more straightforward.
Install EchoProp using npm:
npm install echo-prop
To create a single reactive property, use the createEchoProp
function:
import { createEchoProp } from 'echo-prop';
// Example target object
const target = {};
// Create a reactive property
const prop = createEchoProp(target, 'value', 10, {
replayCount: 1, // Keep 1 previous value in history
validate: (newValue, oldValue) => newValue >= 0, // Validation function
log: true, // Enable logging for validation failures
useExistingValueAsInitial: true // Use existing value if initialValue is null (default: true)
});
// Subscribe to changes
prop.subscribe((newValue) => console.log('New value:', newValue));
// Update the property value
target.value = 20; // Outputs: New value: 20
// Access the observable
const valueObservable = target.value$;
To add multiple reactive properties at once, use createEchoProps
:
import { createEchoProps } from 'echo-prop';
const target = {};
// Define initial values for properties
const propertyBook = {
score: 0,
health: 100
};
// Create reactive properties
const props = createEchoProps(target, propertyBook, {
replayCount: 1,
validate: (newValue, oldValue) => newValue >= 0,
useExistingValueAsInitial: true // Use existing value if initialValue is null (default: true)
});
// Subscribe to a specific property
target.score$.subscribe((newScore) => console.log('New score:', newScore));
// Update the property
target.score = 5; // Outputs: New score: 5
createEchoProp(target, propertyName, initialValue, config)
Creates a reactive property on the target
object.
addAsObservableToTarget
(Boolean, default: true
): Adds the observable to target
with the name <propertyName>$
.replayCount
(Number, default: 1
): Number of previous values the observable will remember.validate
(Function, default: null
): Optional validation function with the signature (newValue, oldValue) => Boolean
.log
(Boolean, default: false
): If true, logs a warning when validation fails.useExistingValueAsInitial
(Boolean, default: true
): Uses the existing property value as the initial value if initialValue
is null
or undefined
.Returns an object:
value (Any)
: The current value of the property.name (String)
: The name of the property.subscribe(callback)
: Subscribe to property changes.asObservable()
: Access the observable for custom handling.complete()
: Complete the observable.createEchoProps(target, propertyBook, config)
Creates multiple reactive properties on the target
object.
createEchoProp
.Returns an array of reactive property objects for custom management.
EchoProp is licensed under the MIT License.
FAQs
A lightweight library for creating reactive properties with RxJS
The npm package echo-prop receives a total of 0 weekly downloads. As such, echo-prop popularity was classified as not popular.
We found that echo-prop 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.