Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

key-tree-store

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

key-tree-store - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

11

key-tree-store.js

@@ -70,4 +70,15 @@ var slice = Array.prototype.slice;

// run all matches with optional context
KeyTreeStore.prototype.run = function (keypath, context) {
this.get(keypath).forEach(function (fn) {
if (context) {
fn.call(context);
} else {
fn();
}
});
};
module.exports = KeyTreeStore;

2

package.json
{
"name": "key-tree-store",
"description": "Simple tool for storing/retrieving objects events based hierarchical keypaths.",
"version": "1.0.0",
"version": "1.1.0",
"author": "Henrik Joreteg <henrik@andyet.net>",

@@ -6,0 +6,0 @@ "bugs": {

@@ -68,2 +68,23 @@ # key-tree-store

running items:
```javascript
// as a shortcut, there's also the `run` method
// to help you run functions that match they keypath
// this assumes you're storing functions, of course.
var KeyTree = require('key-tree-store');
var tree = new KeyTree();
tree.add('key.path', function () {
console.log('function ran!');
});
tree.run('key'); //=> function ran!
// you can also optionally pass a context to run them with
tree.run('key', {some: 'object'});
```
## credits

@@ -70,0 +91,0 @@

@@ -46,1 +46,46 @@ var test = require('tape');

});
test('`run`', function (t) {
var tree = new KeyTree();
var oneRan, twoRan;
var oneContext, twoContext;
var one = function () {
oneRan = true;
oneContext = this;
};
var two = function () {
twoRan = true;
twoContext = this;
};
function reset() {
oneRan = false;
twoRan = false;
oneContext = null;
twoContext = null;
}
reset();
tree.add('one', one);
tree.add('two', two);
tree.run();
t.ok(oneRan);
t.ok(twoRan);
reset();
tree.run('one');
t.ok(oneRan);
t.notOk(twoRan);
reset();
var context = {};
tree.run('one', context)
t.equal(oneContext, context);
t.end();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc