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.3.11 to 4.3.12

2

ampersand-state.js

@@ -430,3 +430,3 @@ var _ = require('underscore');

for (coll in this._collections) {
this[coll] = new this._collections[coll]([], {parent: this});
this[coll] = new this._collections[coll](null, {parent: this});
}

@@ -433,0 +433,0 @@ },

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

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

@@ -58,3 +58,3 @@ # ampersand-state

When creating an instance of a state object, you can pass in the initial values of the **attributes** which will be [set](#ampersand-state-set) on the model. Unless [extraProperties](#amperand-state-extra-properties) is set to `allow`, you will need to have defined these attributes in `props` or `session`.
When creating an instance of a state object, you can pass in the initial values of the **attributes** which will be [set](#ampersand-state-set) on the state. Unless [extraProperties](#amperand-state-extra-properties) is set to `allow`, you will need to have defined these attributes in `props` or `session`.

@@ -75,7 +75,7 @@ If you have defined an **initialize** function for your subclass of State, it will be invoked at creation time.

* `[parse]` {Boolean} - whether to call the class's [parse](#ampersand-state-parse) function with the initial attributes. _Defaults to `false`_.
* `[parent]` {AmpersandState} - pass a reference to a model's parent to store on the model.
* `[parent]` {AmpersandState} - pass a reference to a state's parent to store on the state.
### idAttribute `model.idAttribute`
### idAttribute `state.idAttribute`
The attribute that should be used as the unique id of the model - typically the name of the property representing the model's id on the server. `getId` uses this to determine the id for use when constructing a model's url for saving to the server.
The attribute that should be used as the unique id of the state. `getId` uses this to determine the id for use when constructing a model's url for saving to the server.

@@ -99,25 +99,25 @@ Defaults to `'id'`.

### getId `model.getId()`
### getId `state.getId()`
Get ID of model per `idAttribute` configuration. Should *always* be how ID is determined by other code.
Get ID of state per `idAttribute` configuration. Should *always* be how ID is determined by other code.
### namespaceAttribute `model.namespaceAttribute`
### namespaceAttribute `state.namespaceAttribute`
The property name that should be used as a namespace. Namespaces are completely optional, but exist in case you need to make an additionl distinction between models, that may be of the same type, with potentially conflicting IDs but are in fact different.
The property name that should be used as a namespace. Namespaces are completely optional, but exist in case you need to make an additionl distinction between states, that may be of the same type, with potentially conflicting IDs but are in fact different.
Defaults to `'namespace'`.
### getNamespace `model.getNamespace()`
### getNamespace `state.getNamespace()`
Get namespace of model per `namespaceAttribute` configuration. Should *always* be how namespace is determined by other code.
Get namespace of state per `namespaceAttribute` configuration. Should *always* be how namespace is determined by other code.
### typeAttribute
The property name that should be used to specify what type of model this is. This is optional, but specifying a model type types provides a standard, yet configurable way to determine what type of model it is.
The property name that should be used to specify what type of state this is. This is optional, but specifying a state type types provides a standard, yet configurable way to determine what type of state it is.
Defaults to `'modelType'`.
### getType `model.getType()`
### getType `state.getType()`
Get type of model per `typeAttribute` configuration. Should *always* be how type is determined by other code.
Get type of state per `typeAttribute` configuration. Should *always* be how type is determined by other code.

@@ -152,3 +152,3 @@ ### extraProperties `AmpersandState.extend({ extraProperties: 'allow' })`

var stateC = new StateC({ foo: 'bar' })
//=> TypeError('No foo property defined on this model and extraProperties not set to "ignore" or "allow".');
//=> TypeError('No foo property defined on this state and extraProperties not set to "ignore" or "allow".');
```

@@ -160,3 +160,3 @@

This is used for building the default `url` property, etc.
This is used for building the default `url` property, etc.

@@ -191,9 +191,9 @@ Which is why you can do this:

### isNew `model.isNew()`
### isNew `state.isNew()`
Has this model been saved to the server yet? If the model does not yet have an id (using `getId()`), it is considered to be new.
Has this state been saved to the server yet? If the state does not yet have an id (using `getId()`), it is considered to be new.
### escape `model.escape()`
### escape `state.escape()`
Similar to `get`, but returns the HTML-escaped version of a model's attribute. If you're interpolating data from the model into HTML, using **escape** to retrieve attributes will help prevent XSS attacks.
Similar to `get`, but returns the HTML-escaped version of a state's attribute. If you're interpolating data from the state into HTML, using **escape** to retrieve attributes will help prevent XSS attacks.

@@ -208,5 +208,5 @@ ```

### isValid `model.isValid()`
### isValid `state.isValid()`
Check if the model is currently in a valid state, it does this by calling the `validate` method, of your model if you've provided one.
Check if the state is currently in a valid state, it does this by calling the `validate` method, of your state if you've provided one.

@@ -249,3 +249,3 @@

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.
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 state.

@@ -355,3 +355,3 @@ Instead, if you want to default a property to an array or object you can set `default` to a function like this

**parse** is called when the model is initialized allowing the attributes to be modified/remapped/renamed/etc before they are actually applied to the model. In ampersand-state, parse is only called when the model is first initialized, and only if `{ parse: true }` is passed to the constructor 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 first initialized, and only if `{ parse: true }` is passed to the constructor options:

@@ -383,3 +383,3 @@ ```javascript

Serialize the state object into a plain object, ready for sending to the server (typically called via [toJSON](#ampersand-state-tojson)). Of the model's properties, only `props` is returned, `session` and `derived` are omitted. 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)). Of the state's properties, only `props` is returned, `session` and `derived` are omitted. Will also serialize any `children` or `collections` by calling their serialize methods.

@@ -456,3 +456,3 @@

Return a copy of the object's previous attributes (the state before the last `"change"` event). Useful for getting a diff between versions of a model, or getting back to a valid state after an error occurs.
Return a copy of the object's previous attributes (the state before the last `"change"` event). Useful for getting a diff between versions of a state, or getting back to a valid state after an error occurs.

@@ -462,11 +462,11 @@

Determine if the model has been modified since the last `"change"` event. If an attribute name is passed, determine if that one attribute has changed.
Determine if the state has been modified since the last `"change"` event. If an attribute name is passed, determine if that one attribute has changed.
### 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 model, 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.
### toJSON `state.toJSON()`
Return a shallow copy of the model's attributes for JSON stringification. This can be used for persistence, serialization, or for 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 for 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.

@@ -473,0 +473,0 @@ Calls [serialize](#ampersand-state-serialize) to determine which values to return in the object. Will be called implicitly by JSON.stringify.

@@ -913,2 +913,28 @@ var tape = require('tape');

test('issue #82, child collections should not be cleared if they add data to themselves when instantiated', function (t) {
var Widget = State.extend({
props: {
title: 'string'
}
});
var Widgets = Collection.extend({
initialize: function () {
// some collections read from data they have immediate access to
// like localstorage, or whatnot. This should not be wiped out
// when instantiated by parent.
this.add([{title: 'hi'}]);
},
model: Widget
});
var Parent = State.extend({
collections: {
widgets: Widgets
}
});
var parent = new Parent();
t.equal(parent.widgets.length, 1, 'should contain data added by initialize method of child collection');
t.end();
});
test('listens to child events', function (t) {

@@ -1105,3 +1131,3 @@ var GrandChild = State.extend({

test.only('Issue: #75 `state` property from undefined -> state', function (t) {
test('Issue: #75 `state` property from undefined -> state', function (t) {
t.plan(2);

@@ -1108,0 +1134,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