Socket
Socket
Sign inDemoInstall

classified-magic

Package Overview
Dependencies
1
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.4 to 0.1.5

29

magic.js

@@ -198,3 +198,3 @@ var classified = require('classified'),

if(typeof descriptor !== 'undefined') {
desciptor.configurable = true;
descriptor.configurable = true;
}

@@ -204,6 +204,12 @@

};
magic.getOwnPropertyNames = function () {
return Object.getOwnPropertyNames(instance);
};
magic.get = function(receiver, name) {
//if it exists
if(typeof instance[name] !== 'undefined' || _isMagicBinded()) {
if(typeof instance[name] !== 'undefined'
|| _isMagicBinded()
|| name.indexOf('___') === 0) {
return instance[name];

@@ -219,3 +225,5 @@ }

//if it exists
if(typeof instance[name] !== 'undefined' || _isMagicBinded()) {
if(typeof instance[name] !== 'undefined'
|| _isMagicBinded()
|| name.indexOf('___') === 0) {
instance[name] = value;

@@ -243,2 +251,6 @@ return;

magic.has = function(name) {
if(name.indexOf('___') === 0) {
return instance.hasOwnProperty(name);
}
//if enum is set

@@ -249,12 +261,15 @@ if(typeof instance.___has === 'function') {

return Object.keys(instance);
return instance.hasOwnProperty(name);
};
magic.delete = function(name) {
if(instance.hasOwnProperty(name) || name.indexOf('___') === 0) {
delete instance[name];
return;
}
//if enum is set
if(!_isMagicBinded() && typeof instance.___delete === 'function') {
return instance.___delete.call(instance, name);
instance.___delete.call(instance, name);
}
delete instance[name];
};

@@ -261,0 +276,0 @@

{
"name": "classified-magic",
"description": "OOP for NodeJS with magic",
"version": "0.1.4",
"version": "0.1.5",
"author": {

@@ -25,3 +25,3 @@ "name": "Christian Blanquera",

"dependencies": {
"classified": "0.1.2"
"classified": "0.1.3"
},

@@ -28,0 +28,0 @@ "main": "./magic.js",

@@ -6,49 +6,47 @@ var assert = require('assert');

var Root = classified(function() {
var prototype = {
data: {},
SOME_CONSTANT: 'foo',
sampleProperty: 4.5,
sampleDeepProperty: {
sample1: 'Hello',
sample2: [4, 5, 6, 7],
sample3: {
bool : true,
regex : /^abc/,
date : new Date(),
string : String
}
},
this.data = {};
this.SOME_CONSTANT = 'foo';
this.sampleProperty = 4.5;
this.sampleDeepProperty = {
sample1: 'Hello',
sample2: [4, 5, 6, 7],
sample3: {
bool : true,
regex : /^abc/,
date : new Date(),
string : String
}
};
//protected
_sampleProperty: 5.5,
_sampleDeepProperty: {
sample1: '_Hello',
sample2: [8, 9, 0, 1]
},
this._sampleProperty = 5.5;
this._sampleDeepProperty = {
sample1: '_Hello',
sample2: [8, 9, 0, 1]
};
//private
__sampleProperty: 6.5,
__sampleDeepProperty: {
sample1: '__Hello',
sample2: [12, 13, 14, 15]
}
this.__sampleProperty = 6.5;
this.__sampleDeepProperty = {
sample1: '__Hello',
sample2: [12, 13, 14, 15]
};
prototype.___construct = function() {
this.___construct = function() {
this.constructCalled = true;
};
prototype.sampleMethod = function() {
this.sampleMethod = function() {
return this.SOME_CONSTANT;
};
prototype._sampleMethod = function() {
this._sampleMethod = function() {
return '_bar';
};
prototype.__sampleMethod = function() {
this.__sampleMethod = function() {
return '__zoo';
};
prototype.sampleAccessMethod = function() {
this.sampleAccessMethod = function() {
return this.sampleMethod()

@@ -59,24 +57,21 @@ + this._sampleMethod()

prototype.___get = function(name) {
//console.log('in?', name);
this.___get = function(name) {
return this.data[name];
};
prototype.___set = function(name, value) {
this.___set = function(name, value) {
this.data[name] = value;
};
prototype.___enum = function() {
this.___enum = function() {
return Object.keys(this.data);
};
prototype.___has = function(name, value) {
this.___has = function(name, value) {
return this.data.hasOwnProperty(name);
};
prototype.___delete = function(name) {
this.___delete = function(name) {
delete this.data[name];
};
return prototype;
});

@@ -229,3 +224,3 @@

sampleMethod: function() {
return this.___parent.sampleMethod()
return this.___parent.sampleMethod();
}

@@ -268,3 +263,44 @@ }).trait(Root.definition()).load();

});
it('should be able to freeze and unfreeze data', function(done) {
var child = classified({
_sampleProperty: 0,
sampleOutput: function() {
return this._sampleProperty;
},
sampleMethod: function(callback) {
this.___freeze();
setTimeout(function() {
this._sampleMethod(callback);
}.bind(this));
},
_sampleMethod: function(callback) {
assert.equal(0, this._sampleProperty);
this._sampleProperty = 1;
this.___unfreeze();
callback();
}
}).trait(Root.definition()).load();
child.sampleMethod(function() {
assert.equal('undefined', typeof child._sampleProperty);
});
assert.equal(0, child.sampleOutput());
setTimeout(function() {
assert.equal(1, child.sampleOutput());
assert.equal('undefined', typeof child.___frozen);
assert.equal('undefined', typeof child.___freeze);
assert.equal('undefined', typeof child.___unfreeze);
done();
}, 100);
});
});
});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc