
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
npm i mazzard
Next, we will use mazzard which means we imported it from mazzard.
import mazzard from 'mazzard'
mazzard() // undefined
mazzard returns the first argument as is, if it is not function, array or simple object.
mazzard(1) // 1
mazzard('1') // '1'
mazzard(false) // false
mazzard(null) // null
mazzard(NaN) // NaN
mazzard(Symbol('test')) // Symbol('test')
mazzard(new Map()) // instance of Map
You get the observable object if the first argument is simple object.
const observable = mazzard({test: 'success'})
console.log(observable.test)
// > 'success'
All objects inside observable are observable.
const test = mazzard({observableField: {}})
test // is observable object
test.observableField // is observable object
To have reactions on changes of observable object, use mazzard with a function as the first argument.
The function is observer and runs immediately.
const test = mazzard({})
mazzard(
() => console.log(test.testField) // this is observer
)
// > undefined
test.testField = 'success'
// > 'success'
Observer runs each time when you change observable fields.
You may stop the watching with the first argument of observer.
const test = mazzard({})
mazzard(stop => {
if (test.stop) {
console.log('stop', test.stop)
stop()
} else {
console.log(test.testField)
}
})
// > undefined
test.testField = 'success'
// > 'success'
test.testField = true
// > true
test.stop = 'test message'
// > 'stop', 'test message'
test.testField = 'test'
// nothing happens
Also, you may stop it with that mazzard returns.
const stop = mazzard(() => {})
stop()
If you set the same value which a field have then reaction will not be called.
const test = mazzard({})
mazzard(() => console.log(test.testField))
// > undefined
test.testField = true
// > true
test.testField = true
// nothing happens
If you wanna have only one reaction of observer on several changes, you may use a method of observable object.
const test = mazzard({
update (field1, field2) {
test.field1 = field1
test.field2 = field2
}
})
mazzard(() => {
console.log(test.field1, test.field2)
})
// > undefined, undefined
test.field1 = 'field1'
// > 'field1', undefined
test.field2 = 'field2'
// > 'field1', 'field2'
test.update(1, 2)
// > 1, 2
You may unite changes with action from mazzard.
import {action} from 'mazzard'
const test = mazzard({})
const update = action((field1, field2) => {
test.field1 = field1
test.field2 = field2
})
mazzard(() => console.log(test.field1, test.field2))
// > undefined, undefined
update(1, 2)
// > 1, 2
The same will happen for setters.
const test = mazzard({
set fullName (value) {
const [name, secondName] = value.split(' ')
this.name = name
this.secondName = secondName
}
})
mazzard(() => console.log(test.name, test.secondName))
// > undefined, undefined
test.fullName = 'Mike Mighty'
// > 'Mike', 'Mighty'
Use getters in observable to have computed value with caching.
const test = mazzard({
get fullName () {
return this.name && this.secondName ? `${this.name} ${this.secondName}` : null
}
})
mazzard(() => console.log(test.fullName))
// > null
test.name = 'Mike'
// nothing happens
test.secondName = 'Mighty'
// > 'Mike Mighty'
You get the observable array if the first argument is array.
mazzard([]) // observable array
All changes on the array make reactions.
FAQs
Get reactions on data changes
The npm package mazzard receives a total of 21 weekly downloads. As such, mazzard popularity was classified as not popular.
We found that mazzard 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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.