Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
knockout-undoredo
Advanced tools
Generic undo/redo history-management for knockout observables.
$ npm install knockout-undoredo
Heads up: knockout-undoredo is only available via npm, thus it expects to be run in an node.js environment with require()
and everything. If you want to use it in the browser you'll have to browserify the final code.
import ko from 'knockout';
import UndoManager from 'knockout-undoredo';
class ViewModel {
constructor() {
this.name = ko.observable('Obama');
this.message = ko.pureComputed(() => `Thanks ${this.name()}`);
}
}
const vm = new ViewModel();
// Connect your viewmodel with the undomanager
const undomanager = new UndoManager();
undomanager.startListening(vm);
ko.applyBindings(vm);
// ... and later
console.log(vm.message()); // Thanks Obama
vm.name('Trump');
console.log(vm.message()); // Thanks Trump
undomanager.undo();
console.log(vm.message()); // Thanks Obama
undomanager.redo();
console.log(vm.message()); // Thanks Trump
knockout-undoredo has the ability to collect multiple changes over a defined time as a changeset. These collections will be merged to just one undo/redo step in the history timeline.
// ...
const undomanager = new UndoManager({throttle: 300});
undomanager.startListening(vm);
console.log(vm.message()); // Thanks Obama
vm.name('Trump');
vm.name('Clinton');
console.log(vm.message()); // Thanks Clinton
undomanager.undo();
console.log(vm.message()); // Thanks Obama
Prop | Type | Default | Description |
---|---|---|---|
throttle | integer | 300 | Timeout in which changes will be collected into a changeset |
steps | integer | 30 | Stack size for undoable/redoable changes |
Snapshots are a collection of operations as one undo step. You can configure which operations should be bundled through the throttle
contructor option. Besides that you can always manually trigger a snapshot through undomanager.takeSnapshot()
:
// ...
const undomanager = new UndoManager({throttle: 300});
undomanager.startListening(vm);
console.log(vm.message()); // Thanks Obama
vm.name('Trump');
// Take an early snapshot
undomanager.takeSnapshot()
vm.name('Clinton');
console.log(vm.message()); // Thanks Clinton
undomanager.undo();
console.log(vm.message()); // Thanks Trump
By default all enumerable properties of an object will be subscribed to. If you want to skip a knockout obersvable you can modify the object's enumerable
property:
Object.defineProperty(obj, 'key', {
enumerable: false,
});
If you are one of the lucky guys who can make use of ES2016+ features in your code (i.e. through babel) you can simply import the nonenumerable
decorator from the core-decorators module, or anything alike.
import {nonenumerable} from 'core-decorators';
class Example {
@nonenumerable
unobserved = ko.observable();
}
That way you can still explicitly reference the variable in your code, but it won't be collected by for
-loops and Object.keys
, Object.values
or Object.entries
respectively. Remember that it'll still be visible to Object.getOwnPropertyNames
!
hasUndo()
and hasRedo()
, as an observable of course (2016-12-06)gulp do-release --patch
git push --tags
npm publish
FAQs
Generic undo/redo history-management for knockout observables
We found that knockout-undoredo 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.