Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@swimlane/el-segundo
Advanced tools
I don't always do dirty checking, but when I do, I use El Segundo. The second choice in change detection.
In JavaScript there is no built-in method to determine if values within an Object (or Array) have changed. One well known method is to compare the JSON stringified version of an object to a previous value. For example:
const A = {...};
const prevValue = JSON.stringify(A);
... Do some stuff
const isDirty = prevValue === JSON.stringify(A);
In fact this may be the fasted method to deep dirty check an object in JavaScript. However, this approach has a couple of drawbacks:
JSON.stringify
method must stringify the entire object under test. This can be expensive for large and deeply nested objects.JSON.stringify
does not support circular objects.$
.El Segundo
is designed to encapsulate this dirty checking process while addressing the issues above. It does not, and likely never will, be faster than JSON.stringify
in cases where the object has not changed (i.e. is not dirty), but can realize a notable improvment when the object is dirty.
Method | Early Abort | Circular Objects | Key Order Changes | Non JSON types | Hidden keys |
---|---|---|---|---|---|
El Segundo | ✓ | ✓ | ✓ | ✓ | ✓ |
JSON.stringify | ✘ | ✘ | ✘ | ✓ 1 | ✓ 1 |
deep-diff | ✘ | ✓ | ✓ | ✓ | ✓ 2 |
lodash | ✓ | ✓ | ✓ | ✓ | ✘ 3 |
replacer
parameter... Non JSON types not tested.lodash.isEqualWith
& lodash.isMatchWidth
, but neither options supports all cases.import { ElSegundo } from 'el-segundo';
const A = {...};
const isDirty = new ElSegundo(A);
// Do some stuff
const isDirty = isDirty.check(A); // returns true if any value in A has changed
When an ElSegundo
object is created it internally stores a map of path-value pairs. For example, the following object:
const leia = {
role: 'General',
name: {
first: 'Leia',
second: 'Organa'
},
siblings: [],
$hidden: false,
};
const luke = {
role: 'Jedi',
name: {
first: 'Luke',
second: 'Skywalker'
}
siblings: [leia],
$hidden: true
}
leia.siblings.push(luke);
const isDirty = new ElSegundo(leia);
Would store the cached object:
{
'#': 3,
'#/siblings': 1,
'#/siblings/0': 3,
'#/siblings/0/siblings': 1,
'#/siblings/0/siblings/0': '#',
'#/siblings/0/name': 2,
'#/siblings/0/name/second': 'Skywalker',
'#/siblings/0/name/first': 'Luke',
'#/siblings/0/role': 'Jedi',
'#/name': 2,
'#/name/second': 'Organa',
'#/name/first': 'Leia',
'#/role': 'General'
}
Later, when the value of leia
is checked:
isDirty.check(leia);
The ElSegundo.protyotype.check
method will test equality (===
) of each deeply nested value in leia
to determine if any values have changed. Once a single value has been detected that fails the equality test, the check
is aborted with a return value of true
. If all values pass the equality tests, and all keys within the cached map have been checked, the check
will a return value of false
.
el-segundo
is a Swimlane open-source project; we believe in giving back to the open-source community by sharing some of the projects we build for our application. Swimlane is an automated cyber security operations and incident response platform that enables cyber security teams to leverage threat intelligence, speed up incident response and automate security operations.
1.1.0 (2017-06-20)
FAQs
The second choice in change detection.
The npm package @swimlane/el-segundo receives a total of 290 weekly downloads. As such, @swimlane/el-segundo popularity was classified as not popular.
We found that @swimlane/el-segundo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 42 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.