ampersand-state
Advanced tools
Comparing version 4.2.4 to 4.2.5
@@ -109,3 +109,3 @@ var _ = require('underscore'); | ||
} else if (extraProperties === 'reject') { | ||
throw new TypeError('No "' + attr + '" property defined on ' + (this.type || 'this') + ' model and allowOtherProperties not set.'); | ||
throw new TypeError('No "' + attr + '" property defined on ' + (this.type || 'this') + ' model and extraProperties not set to "ignore" or "allow"'); | ||
} else if (extraProperties === 'allow') { | ||
@@ -112,0 +112,0 @@ def = this._createPropertyDefinition(attr, 'any'); |
{ | ||
"name": "ampersand-state", | ||
"description": "An observable, extensible state object with derived watchable properties.", | ||
"version": "4.2.4", | ||
"version": "4.2.5", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -13,2 +13,3 @@ # ampersand-state | ||
<!-- starthide --> | ||
## browser support | ||
@@ -18,2 +19,3 @@ | ||
](https://ci.testling.com/ampersandjs/ampersand-state) | ||
<!-- endhide --> | ||
@@ -26,2 +28,3 @@ ## install | ||
<!-- starthide --> | ||
## In pursuit of the ultimate observable JS object. | ||
@@ -389,4 +392,99 @@ | ||
In order to deal with this (because sometimes this is a legitimate scenario), `state` simply creates a read-only `isState` property on all state objects that can be used to check whether or a not a given object is in fact a state object no matter what its constructor was. | ||
<!-- endhide --> | ||
## API Reference | ||
### extend `AmpersandState.extend({ })` | ||
To create a State class of your own, you extend AmpersandState and provide instance properties an options for your class. Typically here you will pass any properties (`props`, `session` and `derived` of your state class, and any instance methods to be attached to instances of your class. | ||
```javascript | ||
var Person = AmpersandState.extend({ | ||
props: { | ||
firstName: 'string', | ||
lastName: 'string' | ||
}, | ||
session: { | ||
signedIn: ['boolean', true, false], | ||
}, | ||
derived: { | ||
fullName: { | ||
deps: ['firstName', 'lastName'], | ||
fn: function () { | ||
return this.firstName + ' ' + this.lastName; | ||
} | ||
} | ||
} | ||
}); | ||
``` | ||
### constructor | ||
### initialize | ||
### extraProperties `AmpersandState.extend({ extraProperties: 'allow' })` | ||
Defines how properties that aren't defined in `props`, `session` or `derived` are handled. May be set to `'allow'`, `'reject'` or `'allow'`. | ||
```javascript | ||
var StateA = AmpersandState.extend({ | ||
extraProperties: 'allow', | ||
}); | ||
var stateA = new StateA({ foo: 'bar' }); | ||
stateA.foo === 'bar' //=> true | ||
var StateB = AmpersandState.extend({ | ||
extraProperties: 'ignore', | ||
}); | ||
var stateB = new StateB({ foo: 'bar' }); | ||
stateB.foo === undefined //=> true | ||
var stateC = AmpersandState.extend({ | ||
extraProperties: 'reject' | ||
}); | ||
var stateC = new StateC({ foo: 'bar' }) | ||
//=> TypeError('No foo property defined on this model and extraProperties not set to "ignore" or "allow".'); | ||
``` | ||
### dataTypes | ||
### props/session `AmpersandView.extend({ props: { name: 'string' }, session: { active: 'boolean' })` | ||
Set **props** to an object describing the observed properties of your state class. Props can be defined in three different ways: | ||
* As a string with the expected dataType. One of `string`, `number`, `boolean`, `array`, `object`, `date`, or `any`. Eg: `name: 'string'`. | ||
* An array of `[dataType, required, default]` | ||
* An object `{ type: 'string', required: true, default: '' , allowNull: false}` | ||
### derived | ||
### parse | ||
## serialize | ||
### set | ||
### get | ||
### unset | ||
### toggle | ||
### previousAttribuetes | ||
### hashChanged | ||
### changedAttributes | ||
### toJSON | ||
## Changelog | ||
@@ -393,0 +491,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76383
497