Socket
Socket
Sign inDemoInstall

ampersand-state

Package Overview
Dependencies
Maintainers
2
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.3.6 to 4.3.7

2

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

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

@@ -214,7 +214,8 @@ # ampersand-state

* As a string with the expected dataType. One of `string`, `number`, `boolean`, `array`, `object`, `date`, or `any`. Eg: `name: 'string'`. Can also be set to the name of a custom `dataTypes` if any are defined for the class.
* An array of `[dataType, required, default]`
* An object `{ type: 'string', required: true, default: '' , allowNull: false}`
* An array of `[dataType, required, default]`.
* An object `{ type: 'string', required: true, default: '' , allowNull: false}`.
* `default` will be the value that the property will be set to if it is undefined, either by not being set during initialization, or by being explicit set to undefined.
* If `required` is true, one of two things will happen. If a `default` is set for the property, the property will start with that value, and revert to it after a call to `unset(propertyName)`. If a `default` is not set for the property, an error will be thrown after a call to `unset(propertyName)`.
* Trying to set a property to an invalid type will raise an exception.
* If `required` is true, and a `default` is set for the property, the property will start with that value, and revert to it after a call to `unset(propertyName)`.
* Trying to set a property to an invalid type will raise an exception.
* See [get](#ampersand-state-get) and [set](#ampersand-state-set) for more information about getting and setting properties.

@@ -236,2 +237,21 @@

#### defaulting to objects/arrays
You will get an error if you try to set the default of any property as either an object or array. This is because those two data types are mutable and passed by reference. If you were to default a property to `[]` this would return *the same array* on every new instantiation of the model.
Instead, if you want to default a property to an array or object you can set `default` to a function like this
```javascript
AmpersandModel.extend({
props: {
checkpoints: {
type: 'array',
default: function () { return []; }
}
}
});
```
It's worth noting that both `array` and `object` do this already: they default to empty versions of themselves. You would only need to do this if you wanted to default to an array/object that wasn't empty.
### session `AmpersandView.extend({ session: { name: 'string' } })`

@@ -238,0 +258,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