New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bamboo

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bamboo - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

34

model.js

@@ -6,3 +6,6 @@ var Emitter = require('emitter');

var Model = function(schema, opt) {
var Model = function() {
};
function builder(schema, opt) {
opt = opt || {};

@@ -67,3 +70,3 @@ schema = schema || {};

if (typeof item === 'object') {
prop_val = ArrayModel(Model(item, opt), prop_val, self);
prop_val = ArrayModel(builder(item, opt), prop_val, self);
}

@@ -100,2 +103,3 @@ else {

self.emit('change ' + path, val, old);
self.emit('change', prop, prop_val, old);
}

@@ -109,2 +113,9 @@ }

// handles passing through change events
// should not be inside Object.set below since we need the same function instance
// to properly use .off
function handle_change(inner_prop, prop_val, old) {
self.emit('change ' + prop + '.' + inner_prop, prop_val, old);
}
if (config instanceof Function) {

@@ -120,2 +131,6 @@ // see if it has keys

if (old instanceof Model) {
old.off('change', handle_change);
}
// this handles the case of setting via same object

@@ -130,3 +145,10 @@ // we don't need to call constructor

// need way to identify that this is a model
// nested bamboo Models, we need to pass through the change events
if (prop_val instanceof Model) {
prop_val.on('change', handle_change);
}
self._saved = false;
self.emit('change', prop, prop_val, old);
self.emit('change ' + prop, prop_val, old);

@@ -159,4 +181,4 @@ }

self._saved = false;
self.emit('change ' + prop, prop_val, old);
self.emit('change', prop, prop_val, old);
}

@@ -179,2 +201,3 @@ });

self.emit('change ' + prop, prop_val, old);
self.emit('change', prop, prop_val, old);
}

@@ -185,2 +208,3 @@ });

Construct.prototype = new Model();
Emitter(Construct.prototype);

@@ -361,3 +385,3 @@

more_opt = more_opt || {};
var New_Model = Model(xtend(schema, more_schema), xtend(opt, more_opt));
var New_Model = builder(xtend(schema, more_schema), xtend(opt, more_opt));

@@ -382,2 +406,2 @@ for (var key in Construct) {

module.exports = Model;
module.exports = builder;

6

package.json
{
"name": "bamboo",
"version": "0.0.3",
"version": "0.0.4",
"author": "Roman Shtylman <shtylman@gmail.com>",

@@ -11,3 +11,3 @@ "dependencies": {

"scripts": {
"test": "zuul test/index.js",
"test": "zuul -- test/index.js",
"test-local": "zuul --local 8080 -- test/index.js"

@@ -21,3 +21,3 @@ },

"devDependencies": {
"zuul": "1.0.4",
"zuul": "~1.3.0",
"mocha": "1.14.0",

@@ -24,0 +24,0 @@ "express": "3.4.5",

@@ -10,2 +10,7 @@ // test changing properties

var Author = Model({
name: String,
email: String
});
// placeholder for the Post model

@@ -64,2 +69,61 @@ var Post = Model({

test('nested change - field of submodel', function(done) {
var Post = Model({
title: String,
author: Author
});
var post = Post();
// because author is a nested object
// but will start out undefined
assert.ok(post.author === undefined);
done = after(6, done);
post.once('change author', function(val) {
assert.equal(post.author.name, undefined);
assert.equal(post.author.email, undefined);
done();
});
// need to set author to something first
post.author = {};
post.author.once('change name', function(val) {
assert.equal(val, 'Edgar Poe');
done();
});
post.author.once('change', function(prop, val) {
assert.equal(prop, 'name');
assert.equal(val, 'Edgar Poe');
done();
});
post.on('change author.name', function(val) {
assert.equal(val, 'Edgar Poe');
assert.equal(post.author.name, 'Edgar Poe');
done();
});
// setting this will trigger above change
post.author.name = 'Edgar Poe';
// test that changing stuff on original author model
// will not cause events on post
// if the post author has been changed
var orig = post.author;
post.author = {};
assert.equal(post.author.name, undefined);
post.author.name = 'Edgar Poe';
// should still be event on original model
// not not an event on the post anymore
orig.once('change name', function(val) {
assert.equal(val, 'Foobar');
done();
});
orig.name = 'Foobar';
});
// changing entire subobject should trigger change in primary

@@ -66,0 +130,0 @@ // and subfield

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