ampersand-state
Advanced tools
Comparing version 4.5.6 to 4.6.0
@@ -49,3 +49,2 @@ /*$AMPERSAND_VERSION*/ | ||
assign(Base.prototype, Events, { | ||
@@ -108,4 +107,5 @@ // can be allow, ignore, reject | ||
// on the way out. Before, sending to server, for example. | ||
serialize: function () { | ||
var res = this.getAttributes({props: true}, true); | ||
serialize: function (options) { | ||
var attrOpts = assign({props: true}, options); | ||
var res = this.getAttributes(attrOpts, true); | ||
forEach(this._children, function (value, key) { | ||
@@ -164,3 +164,2 @@ res[key] = this[key].serialize(); | ||
if (!def) { | ||
@@ -460,3 +459,3 @@ // if this is a child model or collection | ||
for (coll in this._collections) { | ||
this[coll] = new this._collections[coll](null, {parent: this}); | ||
this._safeSet(coll, new this._collections[coll](null, {parent: this})); | ||
} | ||
@@ -469,3 +468,3 @@ }, | ||
for (child in this._children) { | ||
this[child] = new this._children[child]({}, {parent: this}); | ||
this._safeSet(child, new this._children[child]({}, {parent: this})); | ||
this.listenTo(this[child], 'all', this._getEventBubblingHandler(child)); | ||
@@ -496,2 +495,11 @@ } | ||
return true; | ||
}, | ||
// expose safeSet method | ||
_safeSet: function safeSet(property, value) { | ||
if (property in this) { | ||
throw new Error('Encountered namespace collision while setting instance property `' + property + '`'); | ||
} | ||
this[property] = value; | ||
return this; | ||
} | ||
@@ -498,0 +506,0 @@ }); |
{ | ||
"name": "ampersand-state", | ||
"description": "An observable, extensible state object with derived watchable properties.", | ||
"version": "4.5.6", | ||
"version": "4.6.0", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -21,16 +21,16 @@ "files": [ | ||
"array-next": "~0.0.1", | ||
"key-tree-store": "^1.2.0", | ||
"key-tree-store": "^1.3.0", | ||
"lodash.assign": "^3.0.0", | ||
"lodash.bind": "^3.1.0", | ||
"lodash.clone": "^3.0.1", | ||
"lodash.defaults": "^3.1.0", | ||
"lodash.clone": "^3.0.3", | ||
"lodash.defaults": "^3.1.2", | ||
"lodash.escape": "^3.0.0", | ||
"lodash.foreach": "^3.0.2", | ||
"lodash.has": "^3.0.0", | ||
"lodash.includes": "^3.1.0", | ||
"lodash.isarray": "^3.0.1", | ||
"lodash.includes": "^3.1.3", | ||
"lodash.isarray": "^3.0.4", | ||
"lodash.isdate": "^3.0.1", | ||
"lodash.isempty": "^3.0.1", | ||
"lodash.isequal": "^3.0.1", | ||
"lodash.isfunction": "^3.0.2", | ||
"lodash.isfunction": "^3.0.6", | ||
"lodash.isnull": "^3.0.0", | ||
@@ -40,3 +40,3 @@ "lodash.isobject": "^3.0.1", | ||
"lodash.isundefined": "^3.0.0", | ||
"lodash.keys": "^3.0.5", | ||
"lodash.keys": "^3.1.2", | ||
"lodash.omit": "^3.1.0", | ||
@@ -50,10 +50,10 @@ "lodash.result": "^3.0.0", | ||
"ampersand-registry": "0.x.x", | ||
"browserify": "^5.9.1", | ||
"browserify": "^11.0.1", | ||
"jshint": "^2.5.3", | ||
"phantomjs": "^1.9.7-15", | ||
"precommit-hook": "^1.0.7", | ||
"run-browser": "~1.2.0", | ||
"tap-spec": "^0.2.0", | ||
"tape": "~2.12.1", | ||
"tape-run": "^0.2.0" | ||
"precommit-hook": "^3.0.0", | ||
"run-browser": "^2.0.2", | ||
"tap-spec": "^4.0.2", | ||
"tape": "^4.0.3", | ||
"tape-run": "^1.1.0" | ||
}, | ||
@@ -74,4 +74,9 @@ "homepage": "https://github.com/ampersandjs/ampersand-state", | ||
"test": "browserify test/index.js | tape-run | tap-spec", | ||
"validate": "jshint .", | ||
"start": "run-browser test/index.js" | ||
"validate": "npm ls", | ||
"start": "run-browser test/index.js", | ||
"lint": "jshint .", | ||
"preversion": "git checkout master && git pull && npm ls", | ||
"publish-patch": "npm run preversion && npm version patch && git push origin master --tags && npm publish", | ||
"publish-minor": "npm run preversion && npm version minor && git push origin master --tags && npm publish", | ||
"publish-major": "npm run preversion && npm version major && git push origin master --tags && npm publish" | ||
}, | ||
@@ -93,3 +98,8 @@ "testling": { | ||
] | ||
} | ||
}, | ||
"pre-commit": [ | ||
"lint", | ||
"validate", | ||
"test" | ||
] | ||
} |
@@ -55,3 +55,3 @@ # ampersand-state | ||
``` | ||
```javascript | ||
class Foo extends AmpersandView | ||
@@ -90,3 +90,3 @@ constructor: (options)-> | ||
``` | ||
```javascript | ||
var Person = AmpersandModel.extend({ | ||
@@ -203,3 +203,3 @@ idAttribute: 'personId', | ||
``` | ||
```javascript | ||
var hacker = new PersonModel({ | ||
@@ -451,5 +451,5 @@ name: "<script>alert('xss')</script>" | ||
The distinction is important because without it, the following would be problemmatic: | ||
The distinction is important because without it, the following would be problematic: | ||
``` | ||
```javascript | ||
var Person = State.extend({ | ||
@@ -543,5 +543,5 @@ props: { | ||
### serialize `state.serialize()` | ||
### 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)). 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. | ||
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. | ||
@@ -548,0 +548,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
61257
719
1
Updatedkey-tree-store@^1.3.0
Updatedlodash.clone@^3.0.3
Updatedlodash.defaults@^3.1.2
Updatedlodash.includes@^3.1.3
Updatedlodash.isarray@^3.0.4
Updatedlodash.isfunction@^3.0.6
Updatedlodash.keys@^3.1.2