ampersand-state
Advanced tools
Comparing version 4.5.2 to 4.5.3
{ | ||
"name": "ampersand-state", | ||
"description": "An observable, extensible state object with derived watchable properties.", | ||
"version": "4.5.2", | ||
"version": "4.5.3", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -6,0 +6,0 @@ "files": [ |
@@ -623,2 +623,42 @@ # ampersand-state | ||
### getAttributes `state.getAttributes([options, raw])` | ||
Returns a shallow copy of the state's attributes while only including the types (props, session, derived) specified by the `options` parameter. The desired keys should be set to `true` on `options` (`props`, `session`, `derived`) if attributes of that type should be returned by `getAttributes`. | ||
The second parameter, `raw`, is a boolean that specifies whether returned values should be the raw value or should instead use the getter associated with its data type. If you are using `getAttributes` to pass data to a template, most of the time you will not want to use the `raw` parameter, since you will want to take advantage of any built-in and custom data types on your state instance. | ||
```javascript | ||
var Person = AmpersandState.extend({ | ||
props: { | ||
firstName: 'string', | ||
lastName: 'string' | ||
}, | ||
session: { | ||
lastSeen: 'date', | ||
active: 'boolean' | ||
}, | ||
derived: { | ||
fullName: { | ||
deps: ['firstName', 'lastName'], | ||
fn: function () { | ||
return this.firstName + ' ' + this.lastName; | ||
} | ||
} | ||
} | ||
}); | ||
var me = new Person({ firstName: 'Luke', lastName: 'Karrys', active: true, lastSeen: 1428430444479 }); | ||
me.getAttributes({derived: true}) //=> { fullName: 'Luke Karrys' } | ||
me.getAttributes({session: true}) //=> { active: true, lastSeen: Tue Apr 07 2015 11:14:04 GMT-0700 (MST) } | ||
me.getAttributes({session: true}, true) //=> { active: true, lastSeen: 1428430444479 } | ||
me.getAttributes({ | ||
props: true, | ||
session: true, | ||
derived: true | ||
}) //=> { firstName: 'Luke', lastName: 'Karrys', active: true, lastSeen: Tue Apr 07 2015 11:14:04 GMT-0700 (MST), fullName: 'Luke Karrys' } | ||
``` | ||
## Changelog | ||
@@ -625,0 +665,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
57210
674