Socket
Socket
Sign inDemoInstall

ampersand-state

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ampersand-state - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

17

ampersand-state.js

@@ -266,7 +266,3 @@ var _ = require('underscore');

if (def.required) {
if (!_.isUndefined(def.default)) {
val = def.default;
} else {
val = this._getDefaultForType(type);
}
val = _.result(def, 'default');
return this.set(attr, val, options);

@@ -294,3 +290,3 @@ } else {

var dataType = this._dataTypes[type];
return dataType && dataType.default && dataType.default();
return dataType && dataType.default;
},

@@ -339,3 +335,3 @@

val = (raw) ? this._values[item] : this[item];
if (typeof val === 'undefined') val = def.default;
if (typeof val === 'undefined') val = _.result(def, 'default');
if (typeof val !== 'undefined') res[item] = val;

@@ -415,4 +411,9 @@ }

if (desc[1] || desc.required) def.required = true;
// set default if defined
def.default = !_.isUndefined(desc[2]) ? desc[2] : desc.default;
if (typeof def.default === 'object') {
throw new TypeError('The default value for ' + name + ' cannot be an object/array, must be a value or a function which returns a value/object/array');
}
def.allowNull = desc.allowNull ? desc.allowNull : false;

@@ -441,3 +442,3 @@ if (desc.setOnce) def.setOnce = true;

}
return def.default;
return _.result(def, 'default');
}

@@ -444,0 +445,0 @@ });

{
"name": "ampersand-state",
"description": "An observable, extensible state object with derived watchable properties.",
"version": "4.0.0",
"version": "4.0.1",
"author": "Henrik Joreteg <henrik@andyet.net>",

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

@@ -101,7 +101,67 @@ var tape = require('tape');

test('should have default array/object properties', function (t) {
var Bar = State.extend({
props: {
list: ['array', true],
hash: ['object', true]
}
});
var bar = new Bar();
var otherBar = new Bar();
t.ok(bar.list !== undefined);
t.ok(bar.hash !== undefined);
//Should create unique instances of the defaults
otherBar.list.push('foo');
otherBar.hash.foo = 'bar';
t.ok(bar.list.length === 0);
t.ok(bar.hash.foo === undefined);
t.end();
});
test('should throw a useful error setting a default value to an array', function (t) {
t.plan(2);
try {
State.extend({
props: { list: ['array', true, []] }
});
} catch (err) {
t.ok(err instanceof TypeError);
t.ok(err.message.match(/value for list cannot be an object\/array/));
}
});
test('should throw a useful error setting a default value to an object', function (t) {
t.plan(2);
try {
State.extend({
props: { list: ['array', true, []] }
});
} catch (err) {
t.ok(err instanceof TypeError);
t.ok(err.message.match(/value for list cannot be an object\/array/));
}
});
test('a default should be settable as a function which returns a value', function (t) {
var Foo = State.extend({
props: {
anObject: ['object', true, function () { return {foo: 'bar'}; }]
}
});
var foo = new Foo();
t.deepEqual(foo.anObject, {foo: 'bar'});
t.end();
});
test('should throw an error setting a derived prop', function (t) {
t.plan(1);
var foo = new Foo();
try { foo.name = 'bob'; }
catch (err) { t.ok(err instanceof TypeError); }
t.end();
});

@@ -108,0 +168,0 @@

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