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

stapes

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stapes - npm Package Compare versions

Comparing version 0.7.1 to 0.8.0

2

package.json

@@ -10,3 +10,3 @@ {

],
"version": "0.7.1",
"version": "0.8.0",
"repository" : {

@@ -13,0 +13,0 @@ "type" : "git",

@@ -16,7 +16,6 @@ //

// Stapes.js : http://hay.github.com/stapes
(function() {
'use strict';
var VERSION = "0.7.1";
var VERSION = "0.8.0";

@@ -107,3 +106,11 @@ // Global counter for all events in all modules (including mixed in objects)

clone : function(obj) {
return _.extend({}, obj);
var type = _.typeOf(obj);
if (type === 'object') {
return _.extend({}, obj);
}
if (type === 'array') {
return obj.slice(0);
}
},

@@ -334,2 +341,4 @@

if (val === null || typeof val === "undefined") {
// This is a special exception for IE, in other browsers the
// method below works all the time
return String(val);

@@ -347,3 +356,5 @@ } else {

// we need the check. Why? I have no clue.
if (_.typeOf(item) === 'object') {
var type = _.typeOf(item);
if (type === 'object' || type === 'array') {
item = _.clone(item);

@@ -403,13 +414,5 @@ }

}
};
_.Module.prototype = {
// create() is deprecated from 0.8.0
create : function() {
throw new Error(''.concat(
'create() on Stapes modules no longer works from 0.8.0. ',
'Check the docs.'
));
},
each : function(fn, ctx) {

@@ -486,3 +489,3 @@ var attr = _.attr(this._guid);

for (var i = 0, l = input.length; i < l; i++) {
_.setAttribute.call(this, _.makeUuid(), input[i]);
_.setAttribute.call(this, _.makeUuid(), input[i], silent || false);
}

@@ -497,3 +500,7 @@ } else {

remove : function(input, silent) {
if (typeof input === "function") {
if (typeof input === 'undefined') {
// With no arguments, remove deletes all attributes
_.attributes[this._guid] = {};
this.emit('change remove');
} else if (typeof input === "function") {
this.each(function(item, key) {

@@ -512,9 +519,9 @@ if (input(item)) {

set : function(objOrKey, value, silent) {
set : function(objOrKey, valueOrSilent, silent) {
if (typeof objOrKey === "object") {
for (var key in objOrKey) {
_.setAttribute.call(this, key, objOrKey[key]);
_.setAttribute.call(this, key, objOrKey[key], valueOrSilent || false);
}
} else {
_.setAttribute.call(this, objOrKey, value, silent || false);
_.setAttribute.call(this, objOrKey, valueOrSilent, silent || false);
}

@@ -552,13 +559,2 @@

// Compatiblity option, this method is deprecated
"create" : function() {
var instance = _.create( _.Module.prototype );
_.addGuid( instance, true );
// Mixin events
Stapes.mixinEvents( instance );
return instance;
},
"extend" : function() {

@@ -565,0 +561,0 @@ return _.extendThis.apply(_.Module.prototype, arguments);

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

/*! Stapes.js v0.7.1 < http://hay.github.com/stapes > */
(function(){"use strict";var a="0.7.1",b=1;if(!Object.create)var c=function(){};var d=Array.prototype.slice,e={attributes:{},eventHandlers:{"-1":{}},guid:-1,addEvent:function(a){e.eventHandlers[a.guid][a.type]||(e.eventHandlers[a.guid][a.type]=[]),e.eventHandlers[a.guid][a.type].push({guid:a.guid,handler:a.handler,scope:a.scope,type:a.type})},addEventHandler:function(a,b,c){var d={},f;typeof a=="string"?(f=c||!1,d[a]=b):(f=b||!1,d=a);for(var g in d){var h=d[g],i=g.split(" ");for(var j=0,k=i.length;j<k;j++){var l=i[j];e.addEvent.call(this,{guid:this._guid||this._.guid,handler:h,scope:f,type:l})}}},addGuid:function(a,c){if(!a._guid||!!c)a._guid=b++,e.attributes[a._guid]={},e.eventHandlers[a._guid]={}},attr:function(a){return e.attributes[a]},clone:function(a){return e.extend({},a)},create:function(a){if(Object.create)return Object.create(a);c.prototype=a;return new c},createSubclass:function(a,b){function g(){if(this instanceof g)this.on&&e.addGuid(this,!0),d.apply(this,arguments);else throw new Error("Please use 'new' when initializing Stapes classes")}a=a||{},b=b||!1;var c=a.superclass.prototype,d=a.hasOwnProperty("constructor")?a.constructor:function(){};b&&e.extend(c,f),g.prototype=e.create(c),g.prototype.constructor=g,e.extend(g,{extend:function(){return e.extendThis.apply(this,arguments)},parent:c,proto:function(){return e.extendThis.apply(this.prototype,arguments)},subclass:function(a){a=a||{},a.superclass=this;return e.createSubclass(a)}});for(var h in a)h!=="constructor"&&h!=="superclass"&&(g.prototype[h]=a[h]);return g},emitEvents:function(a,b,c,f){c=c||!1,f=f||this._guid;var g=d.call(e.eventHandlers[f][a]);for(var h=0,i=g.length;h<i;h++){var j=e.extend({},g[h]),k=j.scope?j.scope:this;c&&(j.type=c),j.scope=k,j.handler.call(j.scope,b,j)}},extend:function(){var a=d.call(arguments),b=a.shift();for(var c=0,e=a.length;c<e;c++){var f=a[c];for(var g in f)b[g]=f[g]}return b},extendThis:function(){var a=d.call(arguments);a.unshift(this);return e.extend.apply(this,a)},makeUuid:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=Math.random()*16|0,c=a=="x"?b:b&3|8;return c.toString(16)})},removeAttribute:function(a,b){b=b||!1;var c=e.trim(a).split(" ");for(var d=0,f=c.length;d<f;d++){var g=e.trim(c[d]);g&&(delete e.attr(this._guid)[g],b||(this.emit("change",g),this.emit("change:"+g),this.emit("remove",g),this.emit("remove:"+g)))}},removeEventHandler:function(a,b){var c=e.eventHandlers[this._guid];if(a&&b){c=c[a];if(!c)return;for(var d=0,f=c.length,g;d<f;d++)g=c[d].handler,g&&g===b&&(c.splice(d--,1),f--)}else a?delete c[a]:e.eventHandlers[this._guid]={}},setAttribute:function(a,b,c){c=c||!1;var d=this.has(a),f=e.attr(this._guid)[a];if(b!==f){e.attr(this._guid)[a]=b;if(c)return;this.emit("change",a),this.emit("change:"+a,b);var g={key:a,newValue:b,oldValue:f||null};this.emit("mutate",g),this.emit("mutate:"+a,g);var h=d?"update":"create";this.emit(h,a),this.emit(h+":"+a,b)}},trim:function(a){return a.replace(/^\s\s*/,"").replace(/\s\s*$/,"")},typeOf:function(a){return a===null||typeof a=="undefined"?String(a):Object.prototype.toString.call(a).replace(/\[object |\]/g,"").toLowerCase()},updateAttribute:function(a,b,c){var d=this.get(a);e.typeOf(d)==="object"&&(d=e.clone(d));var f=b.call(this,d,a);e.setAttribute.call(this,a,f,c||!1)}},f={emit:function(a,b){b=typeof b=="undefined"?null:b;var c=a.split(" ");for(var d=0,f=c.length;d<f;d++){var g=c[d];e.eventHandlers[-1].all&&e.emitEvents.call(this,"all",b,g,-1),e.eventHandlers[-1][g]&&e.emitEvents.call(this,g,b,g,-1),typeof this._guid=="number"&&(e.eventHandlers[this._guid].all&&e.emitEvents.call(this,"all",b,g),e.eventHandlers[this._guid][g]&&e.emitEvents.call(this,g,b))}},off:function(){e.removeEventHandler.apply(this,arguments)},on:function(){e.addEventHandler.apply(this,arguments)}};e.Module=function(){},e.Module.prototype={create:function(){throw new Error("".concat("create() on Stapes modules no longer works from 0.8.0. ","Check the docs."))},each:function(a,b){var c=e.attr(this._guid);for(var d in c){var f=c[d];a.call(b||this,f,d)}},extend:function(){return e.extendThis.apply(this,arguments)},filter:function(a){var b=[],c=e.attr(this._guid);for(var d in c)a.call(this,c[d],d)&&b.push(c[d]);return b},get:function(a){if(typeof a=="string")return this.has(a)?e.attr(this._guid)[a]:null;if(typeof a=="function"){var b=this.filter(a);return b.length?b[0]:null}},getAll:function(){return e.clone(e.attr(this._guid))},getAllAsArray:function(){var a=[],b=e.attr(this._guid);for(var c in b){var d=b[c];e.typeOf(d)==="object"&&!d.id&&(d.id=c),a.push(d)}return a},has:function(a){return typeof e.attr(this._guid)[a]!="undefined"},map:function(a,b){var c=[];this.each(function(d,e){c.push(a.call(b||this,d,e))},b||this);return c},push:function(a,b){if(e.typeOf(a)==="array")for(var c=0,d=a.length;c<d;c++)e.setAttribute.call(this,e.makeUuid(),a[c]);else e.setAttribute.call(this,e.makeUuid(),a,b||!1);return this},remove:function(a,b){typeof a=="function"?this.each(function(c,d){a(c)&&e.removeAttribute.call(this,d,b)}):e.removeAttribute.call(this,a,b||!1);return this},set:function(a,b,c){if(typeof a=="object")for(var d in a)e.setAttribute.call(this,d,a[d]);else e.setAttribute.call(this,a,b,c||!1);return this},size:function(){var a=0,b=e.attr(this._guid);for(var c in b)a++;return a},update:function(a,b,c){typeof a=="string"?e.updateAttribute.call(this,a,b,c||!1):typeof a=="function"&&this.each(function(b,c){e.updateAttribute.call(this,c,a)});return this}};var g={_:e,create:function(){var a=e.create(e.Module.prototype);e.addGuid(a,!0),g.mixinEvents(a);return a},extend:function(){return e.extendThis.apply(e.Module.prototype,arguments)},mixinEvents:function(a){a=a||{},e.addGuid(a);return e.extend(a,f)},on:function(){e.addEventHandler.apply(this,arguments)},subclass:function(a,b){b=b||!1,a=a||{},a.superclass=b?function(){}:e.Module;return e.createSubclass(a,!b)},version:a};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=g),exports.Stapes=g):typeof define=="function"&&define.amd?define(function(){return g}):window.Stapes=g})()
/*! Stapes.js v0.8.0 < http://hay.github.com/stapes > */
(function(){"use strict";var a="0.8.0",b=1;if(!Object.create)var c=function(){};var d=Array.prototype.slice,e={attributes:{},eventHandlers:{"-1":{}},guid:-1,addEvent:function(a){e.eventHandlers[a.guid][a.type]||(e.eventHandlers[a.guid][a.type]=[]),e.eventHandlers[a.guid][a.type].push({guid:a.guid,handler:a.handler,scope:a.scope,type:a.type})},addEventHandler:function(a,b,c){var d={},f;typeof a=="string"?(f=c||!1,d[a]=b):(f=b||!1,d=a);for(var g in d){var h=d[g],i=g.split(" ");for(var j=0,k=i.length;j<k;j++){var l=i[j];e.addEvent.call(this,{guid:this._guid||this._.guid,handler:h,scope:f,type:l})}}},addGuid:function(a,c){if(!a._guid||!!c)a._guid=b++,e.attributes[a._guid]={},e.eventHandlers[a._guid]={}},attr:function(a){return e.attributes[a]},clone:function(a){var b=e.typeOf(a);if(b==="object")return e.extend({},a);if(b==="array")return a.slice(0)},create:function(a){if(Object.create)return Object.create(a);c.prototype=a;return new c},createSubclass:function(a,b){function g(){if(this instanceof g)this.on&&e.addGuid(this,!0),d.apply(this,arguments);else throw new Error("Please use 'new' when initializing Stapes classes")}a=a||{},b=b||!1;var c=a.superclass.prototype,d=a.hasOwnProperty("constructor")?a.constructor:function(){};b&&e.extend(c,f),g.prototype=e.create(c),g.prototype.constructor=g,e.extend(g,{extend:function(){return e.extendThis.apply(this,arguments)},parent:c,proto:function(){return e.extendThis.apply(this.prototype,arguments)},subclass:function(a){a=a||{},a.superclass=this;return e.createSubclass(a)}});for(var h in a)h!=="constructor"&&h!=="superclass"&&(g.prototype[h]=a[h]);return g},emitEvents:function(a,b,c,f){c=c||!1,f=f||this._guid;var g=d.call(e.eventHandlers[f][a]);for(var h=0,i=g.length;h<i;h++){var j=e.extend({},g[h]),k=j.scope?j.scope:this;c&&(j.type=c),j.scope=k,j.handler.call(j.scope,b,j)}},extend:function(){var a=d.call(arguments),b=a.shift();for(var c=0,e=a.length;c<e;c++){var f=a[c];for(var g in f)b[g]=f[g]}return b},extendThis:function(){var a=d.call(arguments);a.unshift(this);return e.extend.apply(this,a)},makeUuid:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=Math.random()*16|0,c=a=="x"?b:b&3|8;return c.toString(16)})},removeAttribute:function(a,b){b=b||!1;var c=e.trim(a).split(" ");for(var d=0,f=c.length;d<f;d++){var g=e.trim(c[d]);g&&(delete e.attr(this._guid)[g],b||(this.emit("change",g),this.emit("change:"+g),this.emit("remove",g),this.emit("remove:"+g)))}},removeEventHandler:function(a,b){var c=e.eventHandlers[this._guid];if(a&&b){c=c[a];if(!c)return;for(var d=0,f=c.length,g;d<f;d++)g=c[d].handler,g&&g===b&&(c.splice(d--,1),f--)}else a?delete c[a]:e.eventHandlers[this._guid]={}},setAttribute:function(a,b,c){c=c||!1;var d=this.has(a),f=e.attr(this._guid)[a];if(b!==f){e.attr(this._guid)[a]=b;if(c)return;this.emit("change",a),this.emit("change:"+a,b);var g={key:a,newValue:b,oldValue:f||null};this.emit("mutate",g),this.emit("mutate:"+a,g);var h=d?"update":"create";this.emit(h,a),this.emit(h+":"+a,b)}},trim:function(a){return a.replace(/^\s\s*/,"").replace(/\s\s*$/,"")},typeOf:function(a){return a===null||typeof a=="undefined"?String(a):Object.prototype.toString.call(a).replace(/\[object |\]/g,"").toLowerCase()},updateAttribute:function(a,b,c){var d=this.get(a),f=e.typeOf(d);if(f==="object"||f==="array")d=e.clone(d);var g=b.call(this,d,a);e.setAttribute.call(this,a,g,c||!1)}},f={emit:function(a,b){b=typeof b=="undefined"?null:b;var c=a.split(" ");for(var d=0,f=c.length;d<f;d++){var g=c[d];e.eventHandlers[-1].all&&e.emitEvents.call(this,"all",b,g,-1),e.eventHandlers[-1][g]&&e.emitEvents.call(this,g,b,g,-1),typeof this._guid=="number"&&(e.eventHandlers[this._guid].all&&e.emitEvents.call(this,"all",b,g),e.eventHandlers[this._guid][g]&&e.emitEvents.call(this,g,b))}},off:function(){e.removeEventHandler.apply(this,arguments)},on:function(){e.addEventHandler.apply(this,arguments)}};e.Module=function(){},e.Module.prototype={each:function(a,b){var c=e.attr(this._guid);for(var d in c){var f=c[d];a.call(b||this,f,d)}},extend:function(){return e.extendThis.apply(this,arguments)},filter:function(a){var b=[],c=e.attr(this._guid);for(var d in c)a.call(this,c[d],d)&&b.push(c[d]);return b},get:function(a){if(typeof a=="string")return this.has(a)?e.attr(this._guid)[a]:null;if(typeof a=="function"){var b=this.filter(a);return b.length?b[0]:null}},getAll:function(){return e.clone(e.attr(this._guid))},getAllAsArray:function(){var a=[],b=e.attr(this._guid);for(var c in b){var d=b[c];e.typeOf(d)==="object"&&!d.id&&(d.id=c),a.push(d)}return a},has:function(a){return typeof e.attr(this._guid)[a]!="undefined"},map:function(a,b){var c=[];this.each(function(d,e){c.push(a.call(b||this,d,e))},b||this);return c},push:function(a,b){if(e.typeOf(a)==="array")for(var c=0,d=a.length;c<d;c++)e.setAttribute.call(this,e.makeUuid(),a[c],b||!1);else e.setAttribute.call(this,e.makeUuid(),a,b||!1);return this},remove:function(a,b){typeof a=="undefined"?(e.attributes[this._guid]={},this.emit("change remove")):typeof a=="function"?this.each(function(c,d){a(c)&&e.removeAttribute.call(this,d,b)}):e.removeAttribute.call(this,a,b||!1);return this},set:function(a,b,c){if(typeof a=="object")for(var d in a)e.setAttribute.call(this,d,a[d],b||!1);else e.setAttribute.call(this,a,b,c||!1);return this},size:function(){var a=0,b=e.attr(this._guid);for(var c in b)a++;return a},update:function(a,b,c){typeof a=="string"?e.updateAttribute.call(this,a,b,c||!1):typeof a=="function"&&this.each(function(b,c){e.updateAttribute.call(this,c,a)});return this}};var g={_:e,extend:function(){return e.extendThis.apply(e.Module.prototype,arguments)},mixinEvents:function(a){a=a||{},e.addGuid(a);return e.extend(a,f)},on:function(){e.addEventHandler.apply(this,arguments)},subclass:function(a,b){b=b||!1,a=a||{},a.superclass=b?function(){}:e.Module;return e.createSubclass(a,!b)},version:a};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=g),exports.Stapes=g):typeof define=="function"&&define.amd?define(function(){return g}):window.Stapes=g})()

@@ -17,6 +17,8 @@ var undef;

var EmptyModule = Stapes.subclass();
test("change events", function() {
expect(8);
expect(12);
var module = Stapes.create();
var module = new EmptyModule();

@@ -27,4 +29,9 @@ module.set('name', 'Johnny');

'change' : function(key) {
ok(key === 'name' || key === 'instrument', 'change event when name is set');
if (key === "silent") {
ok(
key === 'name' ||
key === 'instrument' ||
key === 'screamingobject'
, 'change event when name is set');
if (key === "silent" || key === "silentobject") {
ok(false, "Silent event should not trigger");

@@ -38,2 +45,6 @@ }

'change:silentobject' : function() {
ok(false, "Silent event should not trigger for object");
},
'change:name' : function(value) {

@@ -43,2 +54,6 @@ equal(value, 'Emmylou', 'name attribute changed');

'change:screamingobject' : function() {
ok(true, "Screaming object triggered");
},
'mutate' : function(value) {

@@ -64,3 +79,4 @@ ok(

'create' : function(key) {
equal(key, 'instrument', 'create event on attribute addition');
ok(key === 'instrument' || key === 'screamingobject'
, 'create event on attribute addition');
},

@@ -77,2 +93,10 @@

module.set('silent', 'silent', true); // silent events should not trigger anything
module.set({
silentobject : true
}, true /* no events for silent objects as well */);
module.set({
screamingobject : true
}); /* but we do want them for non-silent objects */
});

@@ -83,3 +107,3 @@

test("update", function() {
var module = Stapes.create();
var module = new EmptyModule();

@@ -123,3 +147,3 @@ module.set('name', 'Johnny');

test("remove", function() {
var module = Stapes.create();
var module = new EmptyModule();
module.set('foo', 'bar');

@@ -167,3 +191,3 @@ module.set('silent', 'silent');

test("each and map with a single object", function() {
var module = Stapes.create();
var module = new EmptyModule();
module.set({

@@ -192,4 +216,4 @@ 'key1': 'value1',

test("context of each() is set to current module", function() {
var module = Stapes.create();
var module2 = Stapes.create();
var module = new EmptyModule();
var module2 = new EmptyModule();

@@ -216,3 +240,3 @@ module.push(1);

test("each with an array", function() {
var module = Stapes.create();
var module = new EmptyModule();
module.push([

@@ -232,3 +256,3 @@ 'value1',

test("filter", function() {
var module = Stapes.create();
var module = new EmptyModule();
module.set({

@@ -239,4 +263,6 @@ 'key1': 'value1',

});
var module2 = Stapes.create().set('key', 'value');
var module2 = new EmptyModule();
module2.set('key', 'value');
module2.filter(function(value, key) {

@@ -283,3 +309,3 @@ ok(value === "value", "Value should be value");

test("off", function() {
var module = Stapes.create();
var module = new EmptyModule();

@@ -333,4 +359,4 @@ var handler = function(){};

test("event scope", function() {
var module1 = Stapes.create();
var module2 = Stapes.create();
var module1 = new EmptyModule();
var module2 = new EmptyModule();
var firstDone = false;

@@ -406,3 +432,5 @@

test("chaining", function() {
var module = Stapes.create().set('foo', true);
var module = new EmptyModule();
module.set('foo', true);
ok(!!module.get && module.get('foo'), "set() should return the object");

@@ -430,2 +458,75 @@ module = module.update('foo', function() { return true; });

module.foo();
});
test("push", function() {
expect(0);
var module = new ( Stapes.subclass() );
// Issue #39, silent flag ignored in an array
module.on('change', function() {
ok(false, "Silent flag should be ignored with array");
});
module.push(true, true);
module.push([1,2,3], true);
});
test("remove", function() {
expect(5);
var module = new ( Stapes.subclass() );
module.set({
'foo' : 1,
'bar' : 2,
'baz' : 3,
'qux' : 4
});
module.on({
'change:foo remove:foo' : function() {
ok(true, 'remove with a key argument');
},
'change:bar remove:bar' : function() {
ok(true, 'remove with a function argument');
}
});
module.remove('foo');
module.remove(function(val) {
return val === 2;
});
module.on({
'remove' : function() {
ok( module.size() === 0, 'remove with no arguments, all attributes removed');
}
});
module.remove();
});
// Not really a bug, but leave this in for documentation purposes
// Issue #40
test("private variables", function() {
var Module = (function() {
return Stapes.subclass({
constructor : function( v ) {
this._val = v;
},
getVal : function() {
return this._val;
}
});
})();
var a = new Module('a');
var b = new Module('b');
ok( a.getVal() === 'a');
ok( b.getVal() === 'b');
});

Sorry, the diff of this file is not supported yet

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