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

can-key-tree

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-key-tree - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

13

CONTRIBUTING.md

@@ -81,8 +81,9 @@ # Contributing to can-key-tree

{
// in build.js export config
outputs: {
"+cjs": { minify: true },
"+amd": { minify: true },
"+global-js": { minify: true }
}
// in build.js export config
outputs: {
"+cjs": { minify: true },
"+amd": { minify: true },
"+global-js": { minify: true }
}
}

@@ -89,0 +90,0 @@ ```

@@ -1,2 +0,2 @@

/*can-key-tree@1.0.0#can-key-tree*/
/*can-key-tree@1.0.1#can-key-tree*/
define([

@@ -3,0 +3,0 @@ 'require',

@@ -1,2 +0,2 @@

/*can-key-tree@1.0.0#can-key-tree*/
/*can-key-tree@1.0.1#can-key-tree*/
var reflect = require('can-reflect');

@@ -3,0 +3,0 @@ function isBuiltInPrototype(obj) {

@@ -130,3 +130,3 @@ /*[global-shim-start]*/

/*can-key-tree@1.0.0#can-key-tree*/
/*can-key-tree@1.0.1#can-key-tree*/
define('can-key-tree', [

@@ -133,0 +133,0 @@ 'require',

@@ -11,11 +11,11 @@ @function can-key-tree.prototype.add add

```js
var keyTree = new KeyTree( [Object, Object, Array] );
const keyTree = new KeyTree( [ Object, Object, Array ] );
function handler1(){}
function handler2(){}
function handler3(){}
function handler1() {}
function handler2() {}
function handler3() {}
keyTree.add(["click", "li", handler1]);
keyTree.add(["click", "li", handler2]);
keyTree.add(["click", "span", handler3]);
keyTree.add( [ "click", "li", handler1 ] );
keyTree.add( [ "click", "li", handler2 ] );
keyTree.add( [ "click", "span", handler3 ] );
```

@@ -26,6 +26,6 @@

{
"click": {
"li": [handler1, handler2],
"span": [handler3]
}
"click": {
"li": [ handler1, handler2 ],
"span": [ handler3 ]
}
}

@@ -32,0 +32,0 @@ ```

@@ -17,3 +17,3 @@ @module {function} can-key-tree

```js
var cities = new KeyTree([Object, Array]);
const cities = new KeyTree( [ Object, Array ] );
```

@@ -26,3 +26,3 @@

```js
cities.add(["Illinois", "Chicago"])
cities.add( [ "Illinois", "Chicago" ] );
```

@@ -34,3 +34,3 @@

{
"Illinois": ["Chicago"]
"Illinois": [ "Chicago" ]
}

@@ -44,7 +44,7 @@ ```

```js
new KeyTree([Object, Map, Array]) // OK
new KeyTree([Object, Set]) // OK
new KeyTree([Object, Array, Array]) // WRONG
new KeyTree([Array, Object]) // WRONG
```
new KeyTree( [ Object, Map, Array ] ); // OK
new KeyTree( [ Object, Set ] ); // OK
new KeyTree( [ Object, Array, Array ] ); // WRONG
new KeyTree( [ Array, Object ] ); // WRONG
```

@@ -86,3 +86,3 @@ Instances of the types are created with `new Type()` for built-in types like Array and Object. User

```js
import KeyTree from 'can-key-tree';
import KeyTree from "can-key-tree";
```

@@ -96,3 +96,3 @@

```js
var keyTree = new KeyTree([Object, Object, Array], {onFirst, onEmpty})
const keyTree = new KeyTree( [ Object, Object, Array ], { onFirst, onEmpty } );
```

@@ -108,9 +108,9 @@

```js
function handler1(){}
function handler2(){}
function handler3(){}
function handler1() {}
function handler2() {}
function handler3() {}
keyTree.add(["click", "li", handler1]);
keyTree.add(["click", "li", handler2]);
keyTree.add(["click", "span", handler3]);
keyTree.add( [ "click", "li", handler1 ] );
keyTree.add( [ "click", "li", handler2 ] );
keyTree.add( [ "click", "span", handler3 ] );
```

@@ -122,6 +122,6 @@

{
"click": {
"li": [handler1, handler2],
"span": [handler3]
}
"click": {
"li": [ handler1, handler2 ],
"span": [ handler3 ]
}
}

@@ -135,3 +135,3 @@ ```

```js
keyTree.get(["click", "li"]) //-> [handler1, handler2]
keyTree.get( [ "click", "li" ] ); //-> [handler1, handler2]
```

@@ -143,3 +143,3 @@

```js
keyTree.get(["click"]) //-> [handler1, handler2, handler3]
keyTree.get( [ "click" ] ); //-> [handler1, handler2, handler3]
```

@@ -152,3 +152,3 @@

```js
keyTree.delete(["click", "li", handler1]);
keyTree.delete( [ "click", "li", handler1 ] );
```

@@ -160,6 +160,6 @@

{
"click": {
"li": [handler2],
"span": [handler3]
}
"click": {
"li": [ handler2 ],
"span": [ handler3 ]
}
}

@@ -171,3 +171,3 @@ ```

```js
keyTree.delete(["click"]);
keyTree.delete( [ "click" ] );
```

@@ -190,3 +190,3 @@

```js
eventTree.add([document.body, "click", "li", handler]);
eventTree.add( [ document.body, "click", "li", handler ] );
```

@@ -197,3 +197,3 @@

```js
eventTree.delete([document.body, "click", "li", handler])
eventTree.delete( [ document.body, "click", "li", handler ] );
```

@@ -206,47 +206,53 @@

// Create an event handler type.
var Delegator = function(parentKey){
// Custom constructors get called with their parentKey.
// In this case, the `parentKey` is the element we will
// delegate from.
this.element = parentKey;
// the nested data `{click: [handlers...], dblclick: [handlers...]}`
this.events = {};
// the callbacks added for each handler.
this.delegated = {};
const Delegator = function( parentKey ) {
// Custom constructors get called with their parentKey.
// In this case, the `parentKey` is the element we will
// delegate from.
this.element = parentKey;
// the nested data `{click: [handlers...], dblclick: [handlers...]}`
this.events = {};
// the callbacks added for each handler.
this.delegated = {};
};
canReflect.assignSymbols( Delegator.prototype, {
// when a new event happens, setup event delegation.
"can.setKeyValue": function(eventName, handlersBySelector){
this.delegated[eventName] = function(ev){
canReflect.each(handlersBySelector, function(handlers, selector){
var cur = ev.target;
do {
if (cur.matches(selector)) {
handlers.forEach(function(handler){
handler.call(cur, ev);
});
}
cur = cur.parentNode;
} while (cur && cur !== ev.currentTarget);
});
};
this.events[eventName] = handlersBySelector;
this.element.addEventListener(eventName,this.delegated[eventName]);
},
"can.getKeyValue": function(eventName) {
return this.events[eventName];
},
// when an event gets removed, teardown event delegation and clean up.
"can.deleteKeyValue": function(eventName) {
this.element.removeEventListener(eventName,this.delegated[eventName]);
delete this.delegated[eventName];
delete this.events[eventName];
},
// we need to know how many items at this node
"can.getOwnEnumerableKeys": function(){
return Object.keys(this.events);
}
});
// when a new event happens, setup event delegation.
"can.setKeyValue": function( eventName, handlersBySelector ) {
this.delegated[ eventName ] = function( ev ) {
canReflect.each( handlersBySelector, function( handlers, selector ) {
let cur = ev.target;
do {
if ( cur.matches( selector ) ) {
handlers.forEach( function( handler ) {
handler.call( cur, ev );
} );
}
cur = cur.parentNode;
} while ( cur && cur !== ev.currentTarget );
} );
};
this.events[ eventName ] = handlersBySelector;
this.element.addEventListener( eventName, this.delegated[ eventName ] );
},
"can.getKeyValue": function( eventName ) {
return this.events[ eventName ];
},
// when an event gets removed, teardown event delegation and clean up.
"can.deleteKeyValue": function( eventName ) {
this.element.removeEventListener( eventName, this.delegated[ eventName ] );
delete this.delegated[ eventName ];
delete this.events[ eventName ];
},
// we need to know how many items at this node
"can.getOwnEnumerableKeys": function() {
return Object.keys( this.events );
}
} );
// create an event tree that stores:

@@ -257,3 +263,3 @@ // - "element being delegated" ->

// - The handlers to call
var eventTree = new KeyTree([Map, Delegator, Object, Array]);
const eventTree = new KeyTree( [ Map, Delegator, Object, Array ] );

@@ -263,15 +269,15 @@

function handler() {
console.log("an li clicked");
console.log( "an li clicked" );
}
eventTree.add([document.body, "click", "li", handler]);
eventTree.add( [ document.body, "click", "li", handler ] );
// to stop listening:
eventTree.delete([document.body, "click", "li", handler]);
eventTree.delete( [ document.body, "click", "li", handler ] );
// to stop listening to all clicks on the body:
eventTree.delete([document.body, "click"]);
eventTree.delete( [ document.body, "click" ] );
// to stop listening to all events on the body:
eventTree.delete([document.body]);
eventTree.delete( [ document.body ] );
```

@@ -278,0 +284,0 @@

@@ -13,11 +13,11 @@ @function can-key-tree.prototype.delete delete

```js
var keyTree = new KeyTree( [Object, Object, Array] );
const keyTree = new KeyTree( [ Object, Object, Array ] );
function handler1(){}
function handler2(){}
function handler3(){}
function handler1() {}
function handler2() {}
function handler3() {}
keyTree.add(["click", "li", handler1]);
keyTree.add(["click", "li", handler2]);
keyTree.add(["click", "span", handler3]);
keyTree.add( [ "click", "li", handler1 ] );
keyTree.add( [ "click", "li", handler2 ] );
keyTree.add( [ "click", "span", handler3 ] );
```

@@ -28,3 +28,3 @@

```js
keyTree.delete(["click", "li", handler1]);
keyTree.delete( [ "click", "li", handler1 ] );
```

@@ -36,6 +36,6 @@

{
"click": {
"li": [handler2],
"span": [handler3]
}
"click": {
"li": [ handler2 ],
"span": [ handler3 ]
}
}

@@ -47,3 +47,3 @@ ```

```js
keyTree.delete(["click"]);
keyTree.delete( [ "click" ] );
```

@@ -50,0 +50,0 @@

@@ -13,11 +13,11 @@ @function can-key-tree.prototype.get get

```js
var keyTree = new KeyTree( [Object, Object, Array] );
const keyTree = new KeyTree( [ Object, Object, Array ] );
function handler1(){}
function handler2(){}
function handler3(){}
function handler1() {}
function handler2() {}
function handler3() {}
keyTree.add(["click", "li", handler1]);
keyTree.add(["click", "li", handler2]);
keyTree.add(["click", "span", handler3]);
keyTree.add( [ "click", "li", handler1 ] );
keyTree.add( [ "click", "li", handler2 ] );
keyTree.add( [ "click", "span", handler3 ] );
```

@@ -28,3 +28,3 @@

```js
keyTree.get(["click", "li"]) //-> [handler1, handler2]
keyTree.get( [ "click", "li" ] ); //-> [handler1, handler2]
```

@@ -35,3 +35,3 @@

```js
keyTree.get(["click"]) //-> [handler1, handler2, handler3]
keyTree.get( [ "click" ] ); //-> [handler1, handler2, handler3]
```

@@ -46,4 +46,4 @@

```js
var keyTree = new KeyTree([Object, Set]);
keyTree.get([]) //-> Set[]
```
const keyTree = new KeyTree( [ Object, Set ] );
keyTree.get( [] ); //-> Set[]
```

@@ -13,11 +13,11 @@ @function can-key-tree.prototype.getNode getNode

```js
var keyTree = new KeyTree( [Object, Object, Array] );
const keyTree = new KeyTree( [ Object, Object, Array ] );
function handler1(){}
function handler2(){}
function handler3(){}
function handler1() {}
function handler2() {}
function handler3() {}
keyTree.add(["click", "li", handler1]);
keyTree.add(["click", "li", handler2]);
keyTree.add(["click", "span", handler3]);
keyTree.add( [ "click", "li", handler1 ] );
keyTree.add( [ "click", "li", handler2 ] );
keyTree.add( [ "click", "span", handler3 ] );
```

@@ -28,3 +28,3 @@

```js
keyTree.getNode(["click"]) //-> { li: [handler1, handler2], span: [handler2] }
keyTree.getNode( [ "click" ] ); //-> { li: [handler1, handler2], span: [handler2] }
```

@@ -31,0 +31,0 @@

@@ -9,10 +9,10 @@ @function can-key-tree.prototype.size size

```js
var keyTree = new KeyTree( [Object, Object, Array] );
const keyTree = new KeyTree( [ Object, Object, Array ] );
function handler1 () {}
function handler2 () {}
function handler1() {}
function handler2() {}
keyTree.size(); //-> 0
keyTree.add( ["click", "li", handler1] );
keyTree.add( ["click", "li", handler2] );
keyTree.add( [ "click", "li", handler1 ] );
keyTree.add( [ "click", "li", handler2 ] );
keyTree.size(); //-> 2

@@ -19,0 +19,0 @@ ```

@@ -9,18 +9,22 @@ @typedef {Object} can-key-tree.types.keyTreeCallbacks KeyTreeCallbacks

```js
var keyTreeCallbacks = {
onFirst: function () {
// called when the first node is added
},
onEmpty: function () {
// called when all nodes are removed
}
const keyTreeCallbacks = {
onFirst: function() {
// called when the first node is added
},
onEmpty: function() {
// called when all nodes are removed
}
};
var keyTree = new KeyTree( [Object, Object, Array], keyTreeCallbacks );
const keyTree = new KeyTree( [ Object, Object, Array ], keyTreeCallbacks );
function handler1 () {}
function handler1() {}
keyTree.add( ["click", "li", handler1] );
keyTree.add( [ "click", "li", handler1 ] );
// onFirst is called with a context (`this`) of the keyTree instance and no arguments
keyTree.delete( [] );
// onEmpty is called with a context (`this`) of the keyTree instance and no arguments

@@ -27,0 +31,0 @@ ```

{
"name": "can-key-tree",
"version": "1.0.1",
"version": "1.0.2",
"description": "Add and remove items to a tree",

@@ -5,0 +5,0 @@ "homepage": "",

@@ -13,3 +13,3 @@ # can-key-tree

```js
import KeyTree from 'can-key-tree';
import KeyTree from "can-key-tree";
```

@@ -23,3 +23,3 @@

```js
var keyTree = new KeyTree([Object, Object, Array], {onFirst, onEmpty})
const keyTree = new KeyTree( [ Object, Object, Array ], { onFirst, onEmpty } );
```

@@ -35,9 +35,9 @@

```js
function handler1(){}
function handler2(){}
function handler3(){}
function handler1() {}
function handler2() {}
function handler3() {}
keyTree.add(["click", "li", handler1]);
keyTree.add(["click", "li", handler2]);
keyTree.add(["click", "span", handler3]);
keyTree.add( [ "click", "li", handler1 ] );
keyTree.add( [ "click", "li", handler2 ] );
keyTree.add( [ "click", "span", handler3 ] );
```

@@ -49,6 +49,6 @@

{
"click": {
"li": [handler1, handler2],
"span": [handler3]
}
"click": {
"li": [ handler1, handler2 ],
"span": [ handler3 ]
}
}

@@ -62,3 +62,3 @@ ```

```js
keyTree.get(["click", "li"]) //-> [handler1, handler2]
keyTree.get( [ "click", "li" ] ); //-> [handler1, handler2]
```

@@ -70,3 +70,3 @@

```js
keyTree.get(["click"]) //-> [handler1, handler2, handler3]
keyTree.get( [ "click" ] ); //-> [handler1, handler2, handler3]
```

@@ -79,3 +79,3 @@

```js
keyTree.delete(["click", "li", handler1]);
keyTree.delete( [ "click", "li", handler1 ] );
```

@@ -87,6 +87,6 @@

{
"click": {
"li": [handler2],
"span": [handler3]
}
"click": {
"li": [ handler2 ],
"span": [ handler3 ]
}
}

@@ -98,3 +98,3 @@ ```

```js
keyTree.delete(["click"]);
keyTree.delete( [ "click" ] );
```

@@ -117,3 +117,3 @@

```js
eventTree.add([document.body, "click", "li", handler]);
eventTree.add( [ document.body, "click", "li", handler ] );
```

@@ -124,3 +124,3 @@

```js
eventTree.delete([document.body, "click", "li", handler])
eventTree.delete( [ document.body, "click", "li", handler ] );
```

@@ -133,47 +133,53 @@

// Create an event handler type.
var Delegator = function(parentKey){
// Custom constructors get called with their parentKey.
// In this case, the `parentKey` is the element we will
// delegate from.
this.element = parentKey;
// the nested data `{click: [handlers...], dblclick: [handlers...]}`
this.events = {};
// the callbacks added for each handler.
this.delegated = {};
const Delegator = function( parentKey ) {
// Custom constructors get called with their parentKey.
// In this case, the `parentKey` is the element we will
// delegate from.
this.element = parentKey;
// the nested data `{click: [handlers...], dblclick: [handlers...]}`
this.events = {};
// the callbacks added for each handler.
this.delegated = {};
};
canReflect.assignSymbols( Delegator.prototype, {
// when a new event happens, setup event delegation.
"can.setKeyValue": function(eventName, handlersBySelector){
this.delegated[eventName] = function(ev){
canReflect.each(handlersBySelector, function(handlers, selector){
var cur = ev.target;
do {
if (cur.matches(selector)) {
handlers.forEach(function(handler){
handler.call(cur, ev);
});
}
cur = cur.parentNode;
} while (cur && cur !== ev.currentTarget);
});
};
this.events[eventName] = handlersBySelector;
this.element.addEventListener(eventName,this.delegated[eventName]);
},
"can.getKeyValue": function(eventName) {
return this.events[eventName];
},
// when an event gets removed, teardown event delegation and clean up.
"can.deleteKeyValue": function(eventName) {
this.element.removeEventListener(eventName,this.delegated[eventName]);
delete this.delegated[eventName];
delete this.events[eventName];
},
// we need to know how many items at this node
"can.getOwnEnumerableKeys": function(){
return Object.keys(this.events);
}
});
// when a new event happens, setup event delegation.
"can.setKeyValue": function( eventName, handlersBySelector ) {
this.delegated[ eventName ] = function( ev ) {
canReflect.each( handlersBySelector, function( handlers, selector ) {
let cur = ev.target;
do {
if ( cur.matches( selector ) ) {
handlers.forEach( function( handler ) {
handler.call( cur, ev );
} );
}
cur = cur.parentNode;
} while ( cur && cur !== ev.currentTarget );
} );
};
this.events[ eventName ] = handlersBySelector;
this.element.addEventListener( eventName, this.delegated[ eventName ] );
},
"can.getKeyValue": function( eventName ) {
return this.events[ eventName ];
},
// when an event gets removed, teardown event delegation and clean up.
"can.deleteKeyValue": function( eventName ) {
this.element.removeEventListener( eventName, this.delegated[ eventName ] );
delete this.delegated[ eventName ];
delete this.events[ eventName ];
},
// we need to know how many items at this node
"can.getOwnEnumerableKeys": function() {
return Object.keys( this.events );
}
} );
// create an event tree that stores:

@@ -184,3 +190,3 @@ // - "element being delegated" ->

// - The handlers to call
var eventTree = new KeyTree([Map, Delegator, Object, Array]);
const eventTree = new KeyTree( [ Map, Delegator, Object, Array ] );

@@ -190,15 +196,15 @@

function handler() {
console.log("an li clicked");
console.log( "an li clicked" );
}
eventTree.add([document.body, "click", "li", handler]);
eventTree.add( [ document.body, "click", "li", handler ] );
// to stop listening:
eventTree.delete([document.body, "click", "li", handler]);
eventTree.delete( [ document.body, "click", "li", handler ] );
// to stop listening to all clicks on the body:
eventTree.delete([document.body, "click"]);
eventTree.delete( [ document.body, "click" ] );
// to stop listening to all events on the body:
eventTree.delete([document.body]);
eventTree.delete( [ document.body ] );
```
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