Socket
Socket
Sign inDemoInstall

ampersand-state

Package Overview
Dependencies
Maintainers
9
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 5.0.2 to 5.0.3

26

ampersand-state.js

@@ -17,3 +17,2 @@ 'use strict';

var result = require('lodash/result');
var bind = require('lodash/bind'); // because phantomjs doesn't have Function#bind
var union = require('lodash/union');

@@ -107,8 +106,9 @@ var Events = require('ampersand-events');

var res = this.getAttributes(attrOpts, true);
forOwn(this._children, bind(function (value, key) {
res[key] = this[key].serialize();
}, this));
forOwn(this._collections, bind(function (value, key) {
res[key] = this[key].serialize();
}, this));
var setFromSerializedValue = function (value, key) {
res[key] = this[key].serialize();
}.bind(this);
forOwn(this._children, setFromSerializedValue);
forOwn(this._collections, setFromSerializedValue);
return res;

@@ -387,3 +387,3 @@ },

var dataType = this._dataTypes[type];
if (dataType && dataType.compare) return bind(dataType.compare, this);
if (dataType && dataType.compare) return dataType.compare.bind(this);
return _isEqual; // if no compare function is defined, use _.isEqual

@@ -394,3 +394,3 @@ },

var dataType = this._dataTypes[type];
if (dataType && dataType.onChange) return bind(dataType.onChange, this);
if (dataType && dataType.onChange) return dataType.onChange.bind(this);
return noop;

@@ -451,5 +451,3 @@ },

var update = function (options) {
options = options || {};
var update = function () {
var newVal = def.fn.call(self);

@@ -514,3 +512,3 @@

if (!this._eventBubblingHandlerCache[propertyName]) {
this._eventBubblingHandlerCache[propertyName] = bind(function (name, model, newValue) {
this._eventBubblingHandlerCache[propertyName] = function (name, model, newValue) {
if (changeRE.test(name)) {

@@ -521,3 +519,3 @@ this.trigger('change:' + propertyName + '.' + name.split(':')[1], model, newValue);

}
}, this);
}.bind(this);
}

@@ -524,0 +522,0 @@ return this._eventBubblingHandlerCache[propertyName];

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

@@ -22,14 +22,14 @@ "files": [

"key-tree-store": "^1.3.0",
"lodash": "^4.11.1"
"lodash": "^4.12.0"
},
"devDependencies": {
"ampersand-collection": "^1.3.2",
"ampersand-collection": "^2.0.0",
"ampersand-registry": "0.x.x",
"coveralls": "^2.11.4",
"istanbul": "^0.4.0",
"jshint": "^2.5.3",
"phantomjs": "^2.1.7",
"coveralls": "^3.0.0",
"istanbul": "^0.4.3",
"jshint": "^2.9.2",
"phantomjs-prebuilt": "^2.1.7",
"precommit-hook": "^3.0.0",
"tape": "^4.0.3",
"zuul": "^3.9.0"
"tape": "^4.5.1",
"zuul": "^3.10.1"
},

@@ -36,0 +36,0 @@ "homepage": "https://github.com/ampersandjs/ampersand-state",

@@ -29,7 +29,7 @@ # ampersand-state

To create a **State** class of your own, you extend **AmpersandState** and provide instance properties and 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.
To create a **State** class of your own, you extend **AmpersandState** and provide instance properties and options for your class. Typically, this is when you'll define the properties (`props`, `session`, and `derived`) of your state class, and any instance methods to be attached to instances of your class.
**extend** correctly sets up the prototype chain, so that subclasses created with **extend** can be further extended as many times as you like.
Definitions like `props`, `session`, `derived` etc will be merged with superclass definitions.
Definitions like `props`, `session`, `derived`, etc. will be merged with superclass definitions.

@@ -56,7 +56,8 @@ ```javascript

`AmpersandState.extend` does more than just copy attributes from one prototype to another. As such it is incompatible with Coffeescript's class-based extend. TypeScript users may have similar issues.
`AmpersandState.extend` does more than just copy attributes from one prototype to another. As such, it is incompatible with CoffeeScript's class-based extend. TypeScript users may have similar issues.
For instance, this will not work since it never actually calls `AmpersandState.extend`:
For instance, this will not work (since it never actually calls `AmpersandState.extend`):
```javascript
// don't do this!
class Foo extends AmpersandView

@@ -73,3 +74,3 @@ constructor: (options)->

If you have defined an `initialize` function for your subclass of State, it will be invoked at creation time.
If you have defined an `initialize` function for your subclass of `State`, it will be invoked at creation time.

@@ -113,3 +114,3 @@ ```javascript

Get ID of state per `idAttribute` configuration. Should *always* be how ID is determined by other code.
Gets the state's ID, per `idAttribute` configuration. Should *always* be how ID is determined by other code.

@@ -138,3 +139,3 @@ ### namespaceAttribute `state.namespaceAttribute`

Defines how properties that aren't defined in `props`, `session` or `derived` are handled. May be set to `'allow'`, `'ignore'` or `'reject'`.
Determines how properties that aren't defined in `props`, `session` or `derived` are handled. May be set to `'allow'`, `'ignore'`, or `'reject'`.

@@ -184,3 +185,3 @@ Defaults to `'ignore'`.

// Without a `collection` reference this
// Without a `collection` reference, this
// widget wouldn't know what URL to build

@@ -193,3 +194,3 @@ // when calling destroy

A special property of states, the **`cid`**, or a client id, is a unique identifier automatically assigned to all states when they are first created. Client ids are handy when the state has not been saved to the server, and so does not yet have its true `id`, but needs a unique id (so it can be rendered in the UI, etc.).
A special property of states, the **`cid`** (or <dfn>client id</dfn>) is a unique identifier automatically assigned to all states when they are first created. Client IDs are handy when the state has not been saved to the server, and so does not yet have its true `id`, but still needs a unique id (for rendering in the UI, and so on).

@@ -227,16 +228,33 @@ ```javascript

ampersand-state defines several built-in datatypes: `string`, `number`, `boolean`, `array`, `object`, `date`, `state`, or `any`. Of these, `object`, `array` and `any` allow for a lot of extra flexibility. However sometimes it may be useful to define your own custom datatypes. Then you can use these types in the `props` below with all their features (like `required`, `default`, etc).
ampersand-state defines several built-in datatypes:
Setting `type` is required and `typeError` will be thrown if it's missing or has not been choosen either from default types or your custom ones.
- `string`
- `number`
- `boolean`
- `array`
- `object`
- `date`
- `state`
- `any`
Of these, `object`, `array`, and `any` allow for a lot of extra flexibility.
However, sometimes it's useful to define your own custom datatypes. Doing so allows you to use them in the `props` below, along with all their features (like `required`, `default`, etc).
Setting `type` is required. A `typeError` will be thrown if it's missing or has not been chosen (either from default types or your custom ones).
To define a type, you generally will provide an object with 4 member functions (though only 2 are usually necessary) `get`, `set`, `default`, and `compare`.
* `set : function(newVal){}; returns {type : type, val : newVal};`: Called on every set. Should return an object with two members: `val` and `type`. If the `type` value does not equal the name of the dataType you defined, a `TypeError` should be thrown.
* `compare : function(currentVal, newVal, attributeName){}; returns boolean`: Called on every `set`. Should return `true` if `oldVal` and `newVal` are equal. Non-equal values will eventually trigger `change` events, unless the state's `set` (not the dataTypes's!) is called with the option `{silent : true}`.
* `onChange : function (value, previousValue, attributeName){};`: Called after the value changes. Useful for automatically setting up or tearing down listeners on properties.
* `get : function(val){} returns val;`: Overrides the default getter of this type. Useful if you want to make defensive copies. For example, the `date` dataType returns a clone of the internally saved `date` to keep the internal state consistent.
* `default : function(){} returns val;`: Returns the default value for this type.
| FUNCTION | RETURNS | DESCRIPTION |
| -------- | -------- | ----------- |
| `set : function(newVal){}` | `{type : type, val : newVal}` | Called on every set. Should return an object with two members: `val` and `type`. If the `type` value does not equal the name of the dataType you defined, a `TypeError` should be thrown. |
| `compare : function(currentVal, newVal, attributeName){}` | `boolean` | Called on every `set`. Should return `true` if `oldVal` and `newVal` are equal. Non-equal values will eventually trigger `change` events, unless the state's `set` (not the dataTypes's!) is called with the option `{silent : true}`. |
| `onChange : function (value, previousValue, attributeName){}` | … | Called after the value changes. Useful for automatically setting up or tearing down listeners on properties. |
| `get : function(val){}` | `val` | Overrides the default getter of this type. Useful if you want to make defensive copies. For example, the `date` dataType returns a clone of the internally saved `date` to keep the internal state consistent. |
| `default : function(){}` | `val` | Returns the default value for this type. |
For example, let's say your application uses a special type of date, `JulianDate`. You'd like to setup this as a type in state, but don't want to just use `any` or `object` as the type. To define it:
For example, let's say your application uses a special type of date: `JulianDate`. You'd like to define this as a `type` in state, but don't want to just use `any` or `object` as the type.
To define it:
```javascript

@@ -308,18 +326,24 @@ // Julian Date is a 'class' defined elsewhere:

The **`props`** object describes the observable properties of your state class. Always pass `props` to `extend`; never set it on an instance, as it won't define new properties.
The **`props`** object describes the observable properties of your state class.
Always pass `props` to `extend`! Never set it on an instance, as it won't define new properties.
Properties can be defined in three different ways:
* As a string with the expected dataType. One of `string`, `number`, `boolean`, `array`, `object`, `date`, or `any`. (Example: `name: 'string'`.) Can also be set to the name of a custom `dataTypes`, if the class defines any.
* An array of `[dataType, required, default]`
* An object `{ type: 'string', required: true, default: '' , values: [], allowNull: false, setOnce: 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 the property has a `default`, it will start with that value, and revert to it after a call to `unset(propertyName)`.
* If the property does not have a `default`, calls to `unset(propertyName)` will throw an error.
* If `values` array is passed, then you'll be able to change a property to one of those values only.
* If `setOnce` is `true`, then you'll be able to set property only once.
* If the property has a `default`, and you don't set the value initially, the property will be permanently set to the default value.
* If the property doesn't have a `default`, and you don't set the value initially, it can be set later, but only once.
* If `test` function is passed, then a negative validation test will be executed every time this property is about to be set. If the validation passes, the function must return `false` to tell **State** to go ahead and set the value. Otherwise, it should return a `string` with the error message describing the validation failure. In this case **State** will throw a `TypeError` with `"Property '<property>' failed validation with error: <errorMessage>"`.
1. As a string with the expected dataType
- One of `string`, `number`, `boolean`, `array`, `object`, `date`, or `any`. (Example: `name: 'string'`.)
- Can also be set to the name of a custom `dataTypes`, if the class defines any.
2. An array of `[dataType, required, default]`
3. An object `{ type: 'string', required: true, default: '' , values: [], allowNull: false, setOnce: false }`
- _`default`_: 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`:
- If the property has a `default`, it will start with that value, and revert to it after a call to `unset(propertyName)`
- Otherwise, calls to `unset(propertyName)` throw an error
- If `values` array is passed, then you'll be able to change the property to one of those values only.
- If `setOnce` is `true`, then you'll be able to set property only once.
- If the property has a `default`, and you don't set the value initially, the property will be permanently set to the default value.
- Otherwise, if you don't set the value initially, it can be set later, but only once.
- If `test` function is passed, then a negative validation test will be executed every time this property is about to be set.
- If the validation passes, the function must return `false` to tell **State** to go ahead and set the value.
- Otherwise, it should return a `string` with the error message describing the validation failure. (In this case, **State** will throw a `TypeError` with `"Property '<property>' failed validation with error: <errorMessage>"`.)

@@ -353,7 +377,8 @@ Trying to set a property to an invalid type will throw an error.

#### reserved prop, session names
The following should not be used as `prop` names for any state object. This of course includes things based on state such as ampersand-model and ampersand-view.
The following should not be used as `prop` names for any state object. This of course includes things based on state such as `ampersand-model` and `ampersand-view`.
If you're consuming an API you don't control, you can re-name keys by overwriting `parse` and `serialize` methods.
If you're consuming an API you don't control, you can rename keys by overwriting `parse` and `serialize` methods.

@@ -364,3 +389,3 @@ `bind`, `changedAttributes`, `cid`, `clear`, `collection`, `constructor`, `createEmitter`, `escape`, `extraProperties`, `get`, `getAttributes`, `getId`, `getNamespace`, `getType`, `hasChanged`, `idAttribute`, `initialize`, `isNew`, `isValid`, `listenTo`, `listenToAndRun`, `listenToOnce`, `namespaceAttribute`, `off`, `on`, `once`, `parent`, `parse`, `previous`, `previousAttributes`, `serialize`, `set`, `stopListening`, `toJSON`, `toggle`, `trigger`, `typeAttribute`, `unbind`, `unset`, `url`

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 dataTypes are mutable and passed by reference. (Thus, if you *did* set a property's default to `['a','b']`, it would return *the same array* on every new instantiation of the state.)
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 dataTypes are mutable and passed by reference. (Thus, if you _did_ set a property's default to `['a','b']`, it would return *the same array* on every new instantiation of the state.)

@@ -380,3 +405,3 @@ Instead, if you want a property to default to an array or an object, just set `default` to a function, like this:

It's worth noting that both `array` and `object` have this behavior built-in: 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.
**NOTE:** Both `array` and `object` have this behavior built-in: 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.

@@ -400,4 +425,6 @@ ### session `AmpersandState.extend({ session: { name: 'string' } })`

Derived properties (also known as computed properties) are properties of the state object that depend on other properties (from `props`, `session`, or even `derived` or the same from state props or children) to determine their value. Best demonstrated with an example:
Derived properties (also known as computed properties) are properties of the state object that depend on other properties to determine their value. They may depend on properties defined in `props`, `session`, or even `derived`&mdash;as well as the same from state props or children.
Best demonstrated with an example:
```javascript

@@ -467,3 +494,3 @@ var Address = AmpersandState.extend({

* `fn` {Function} - A function which returns the value of the computed property. It is called in the context of the current object, so that `this` is set correctly.
* `cache` {Boolean} - Whether to cache the property. Uncached properties are computed everytime they are accessed. Useful if it depends on the current time for example. _Defaults to `true`_.
* `cache` {Boolean} - Whether to cache the property. Uncached properties are computed every time they are accessed. Useful if it depends on the current time for example. _Defaults to `true`_.

@@ -474,3 +501,3 @@ Derived properties are retrieved and fire `change` events just like any other property. However, they cannot be set directly. Caching ensures that the `fn` function is only run when any of the dependencies change, and `change` events are only fired if the result of calling `fn()` has actually changed.

Define child state objects to attach to the object. Attributes passed to the constructor or to `set()` will be proxied to the children/collections. Childen's `change` events are proxied to the parent.
Define child state objects to attach to the object. Attributes passed to the constructor or to `set()` will be proxied to the `children`/`collection`. Children's `change` events are proxied to the parent.

@@ -509,11 +536,11 @@ ```javascript

**note:** If you want to be able to swap out and get a `change` event from a child model, don't use `children` instead, define a prop in `props` of type `state`.
**NOTE:** If you want to be able to swap out and get a `change` event from a child model, don't use `children`. Instead, define a prop in `props` of type `state`.
`children` and `collections` are not just a property of the parent, they're *part* of the parent. When you create the parent, an instance of any children or collections will be instantiated as part of instantiating the parent, whether they have any data or not.
`children` and `collections` are not just a property of the parent; they're _part_ of the parent. When you create the parent, an instance of any children or collections will be instantiated _as part of_ instantiating the parent, whether they have any data or not.
Calling `.set()` on the parent with a nested object will automatically `set()` them on children and collections too. This is super handy for APIs [like this one](https://developer.github.com/v3/repos/#response) that return nested JSON structures.
Calling `.set()` on the parent with a nested object will automatically `set()` them on children and collections, too. This is super handy for APIs [like this one](https://developer.github.com/v3/repos/#response) that return nested JSON structures.
Also, there will be no `change` events triggered if you replace a child with something else after you've instantiated the parent because it's not a true property in the `props` sense. If you need a prop that stores a state instance, define it as such, don't use `children`.
Also, there will be no `change` events triggered if you replace a child with something else after you've instantiated the parent, because it's not a true property in the `props` sense. If you need a prop that stores a state instance, define it as such&mdash;don't use `children`.
The distinction is important because without it, the following would be problematic:
The distinction is important! Without it, the following would be problematic:

@@ -537,3 +564,3 @@ ```javascript

So, while having `children` in addition to props of type `state` may feel redundant they both exist to help disambiguate how they're meant to be used.
So, while having `children` in addition to props of type `state` may feel redundant, they both exist to help disambiguate how they're meant to be used.

@@ -544,3 +571,3 @@ ### collections `AmpersandState.extend({ collections: { widgets: Widgets } })`

**Note:** Currently, events *don't* automatically proxy from collections to parent. This is for efficiency reasons. But there are ongoing discussions about how to best handle this.
**NOTE:** Currently, events _don't_ automatically proxy from collections to parent. This is for efficiency reasons. But there are ongoing discussions about how to best handle this.

@@ -586,4 +613,6 @@ ```javascript

**parse** is called when the state is initialized, allowing the attributes to be modified, remapped, renamed, etc., before they are actually applied to the state. In ampersand-state, `parse` is only called when the state is initialized, and *only* if `{ parse: true }` is passed to the constructor's options:
**parse** is called when the state is initialized, allowing the attributes to be modified, remapped, renamed, etc., before they are actually applied to the state.
In `ampersand-state`, `parse` is only called when the state is initialized, and _only_ if `{ parse: true }` is passed to the constructor's options.
```javascript

@@ -610,14 +639,19 @@ var Person = AmpersandState.extend({

**parse** is arguably more useful in ampersand-model, where data typically comes from the server.
(**parse** is arguably more useful in `ampersand-model`, where data typically comes from the server.)
### serialize `state.serialize([options])`
Serialize the state object into a plain object, ready for sending to the server (typically called via [toJSON](#ampersand-state-tojson)). By default, of the state's properties only `props` is returned, while `session` and `derived` are omitted. You can serialize `session` or `derived` attributes as well by passing in a options object. The options object should match that accepted by `.getAttributes(...)`. This method will also serialize any `children` or `collections` by calling their serialize methods.
Serialize the state object into a plain object, ready for sending to the server (typically called via [`toJSON`](#ampersand-state-tojson)).
By default, this returns only properties defined in `props`, omitting properties in `session` and `derived`. To also serialize `session` or `derived` attributes, you can pass in a options object. The options object should match that accepted by `.getAttributes(...)`.
This method will also serialize any `children` or `collections` by calling their `serialize` methods.
### get `state.get(attribute); state[attribute]; state.firstName`
Get the current value of an attribute from the state object. Attributes can be accessed directly, or a call to the Backbone style `get`. So these are all equivalent:
Get the current value of an attribute from the state object. Attributes can be accessed directly, or a call to the Backbone style `get`.
```javascript
// these are all equivalent
person.get('firstName');

@@ -628,8 +662,10 @@ person['firstName'];

Get will retrieve `props`, `session` or `derived` properties all in the same way.
Get will retrieve `props`, `session`, or `derived` properties all in the same way.
### set `state.set(attributes, [options]); state.firstName = 'Henrik';`
Sets an attribute, or multiple attributes, on the state object. If any of the state object's attributes change, it will trigger a `"change"` event. Change events for specific attributes are also triggered, which you can listen to as well. For example: `"change:firstName"` and `"change:content"`. If the changes update any `derived` properties on the object, their values will be updated, and change events fired as well.
Sets an attribute, or multiple attributes, on the state object. If any of the state object's attributes change, it will trigger a `"change"` event.
Change events for specific attributes are also triggered, which you can listen for as well. For example: `"change:firstName"` and `"change:content"`. If the update affects any `derived` properties, their values will be updated and fire `"change"` events as well.
Attributes can be set directly, or via a call to the backbone style `set` (useful if you wish to update multiple attributes at once):

@@ -648,7 +684,7 @@

_Note: when passing an object as the `attributes` argument, only that object's own enumerable properties (i.e. those that can be accessed with `Object.keys(object)`) are read and set. This behaviour is new as of v5.0.0, as prior version relied on `for...in` to access an object's properties, both owned by that object and those inherited through the prototypal chain._
**NOTE:** When passing an object as the `attributes` argument, only that object's own enumerable properties (i.e. those that can be accessed with `Object.keys(object)`) are read and set. This behaviour is new as of v5.0.0. (Prior version relied on `for...in` to access an object's properties, both owned by that object and those inherited through the prototypal chain.)
### unset `state.unset(attribute|attributes[], [options])`
Clear the named attribute or an array of named attributes from the state object. Fires a `"change"` event and a `"change:attributeName"` event unless `silent` is passed as an option.
Clear the named attribute, or an array of named attributes, from the state object. Fires a `"change"` event and a `"change:attributeName"` event unless `silent` is passed as an option.

@@ -677,3 +713,4 @@ If the attribute being unset is `required` and has a `default` value as defined in either `props` or `session`, it will be set to that value, otherwise it will be `undefined`.

Shortcut to toggle boolean properties, or cycle through array of specified property's `values` (see `values` option section and example below).
Shortcut to toggle boolean properties, _or_ to cycle through array of specified property's `values`. (See the `values` option and example, below.)
When you reach the last available value from given array, `toggle` will go back to the beginning and use first one.

@@ -716,18 +753,20 @@

**note:** that this will only be `true` if checked inside a handler while the various `change` events are firing. Once the change events are done this will always return `false`. This has nothing to do with determining whether a property has changed since the last time it was saved to the server.
**NOTE:** This will only be `true` if checked inside a handler while the various `change` events are firing. Once the change events are done, this will always return `false`. This has nothing to do with determining whether a property has changed since the last time it was saved to the server.
### changedAttributes `state.changedAttributes([objectToDiff])`
Return an object containing all the attributes that have changed, or `false` if there are no changed attributes. Useful for determining what parts of a view need to be updated and/or what attributes need to be persisted to the server. Unset attributes will be set to undefined. You can also pass an attributes object to diff against the state, determining if there *would be* a change.
Return an object containing all the attributes that have changed, or `false` if there are no changed attributes. Useful for determining what parts of a view need to be updated and/or what attributes need to be persisted to the server. Unset attributes will be set to `undefined`. You can also pass an attributes object to diff against the state, determining if there _would_ be a change.
**note:** that if passing an attributes object to diff against, only changes to properties defined on the model will be detected. This means that changes to children or collections will *not* be returned as changes by this method.
**NOTE:** When passing an attributes object to diff against, only changes to properties defined on the model will be detected. This means that changes to children or collections will _not_ be returned as changes by this method.
**note:** that this will only return values if checked inside a handler while the various `change` events are firing. Once the change events are done this will always be return an empty object. This has nothing to do with determining which properties have been changed since the last time it was saved to the server.
**NOTE:** This will only return values if checked inside a handler for `"change"` events (i.e. while the events are firing). Once the change events are done, this will always return an empty object. This has nothing to do with determining which properties have been changed since the last time it was saved to the server.
### toJSON `state.toJSON()`
Return a shallow copy of the state's attributes for JSON stringification. This can be used for persistence, serialization, or augmentation, before being sent to the server. The name of this method is a bit confusing, as it doesn't actually return a JSON string — but I'm afraid that it's the way that the JavaScript API for `JSON.stringify` works.
Return a shallow copy of the state's attributes for JSON stringification. This can be used for persistence, serialization, or augmentation, before being sent to the server.
Calls [serialize](#ampersand-state-serialize) to determine which values to return in the object. Will be called implicitly by `JSON.stringify`.
(The name of this method is a bit confusing, as it doesn't actually return a JSON string&mdash;but I'm afraid that it's the way that the JavaScript API for `JSON.stringify` works.)
Calls [`serialize`](#ampersand-state-serialize) to determine which values to return in the object. Will be called implicitly by `JSON.stringify`.
```javascript

@@ -744,5 +783,5 @@ var me = new Person({ firstName: 'Phil', lastName: 'Roberts' });

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`.
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.
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 dataType. 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 dataTypes on your state instance.

@@ -749,0 +788,0 @@ ```javascript

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