Socket
Socket
Sign inDemoInstall

ampersand-state

Package Overview
Dependencies
Maintainers
4
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.4.3 to 4.4.4

4

ampersand-state.js

@@ -196,4 +196,4 @@ /*$AMPERSAND_VERSION*/

// enforce `setOnce` for properties if set
if (def.setOnce && currentVal !== undefined && hasChanged) {
throw new TypeError('Property \'' + key + '\' can only be set once.');
if (def.setOnce && currentVal !== undefined && hasChanged && !initial) {
throw new TypeError('Property \'' + attr + '\' can only be set once.');
}

@@ -200,0 +200,0 @@

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

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

@@ -312,2 +312,4 @@ # ampersand-state

* If `setOnce` is true, then you'll be able to set property only once.
* If used in combination with a `default` and you instantiate without that value, the default becomes the first value `set`. Thus cannot be set again.
* If you don't have a default and don't set the value initially it can be set later, but only once.
* Trying to set a property to an invalid type will raise an exception.

@@ -314,0 +316,0 @@

@@ -1534,1 +1534,51 @@ var tape = require('tape');

});
test('#118 setOnce can be used with default string', function (t) {
var TimeRange = State.extend({
props: {
timezone: {
type: 'string',
default: 'something that can only be set as the default',
setOnce: true
}
}
});
var tr = new TimeRange();
t.throws(function () {
tr.timezone = 'new thing';
}, 'since it has a default, this should throw');
var tr2;
t.doesNotThrow(function () {
tr2 = new TimeRange({timezone: 'my thing'});
}, 'if we set on init, should overwrite default');
t.throws(function () {
tr.timezone = 'new thing';
}, 'should now fail since its been set');
var OtherTimeRange = State.extend({
props: {
timezone: {
type: 'string',
setOnce: true
}
}
});
tr = new OtherTimeRange();
t.doesNotThrow(function () {
tr.timezone = 'thing';
}, 'should not throw first time');
t.throws(function () {
tr.timezone = 'other thing';
}, 'throws second time');
t.end();
});
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