Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ampersand-collection

Package Overview
Dependencies
Maintainers
5
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ampersand-collection - npm Package Compare versions

Comparing version 1.6.0 to 1.6.1

2

package.json
{
"name": "ampersand-collection",
"version": "1.6.0",
"version": "1.6.1",
"author": "Henrik Joreteg <henrik@andyet.net>",

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

@@ -225,3 +225,30 @@ # ampersand-collection

### parse `collection.parse(data, [options])`
The parse method gets called if the `{parse: true}` option is passed when calling `collection.set` method. By default, `parse` simply returns the data it was passed, but can be overwritten through `.extend` to provide any additional parsing logic to extract the array of data that should be stored in the collection. This is most commonly used when processing data coming back from an ajax request. The response from an API may look like this:
```javascript
{
"limit": 100,
"offset": 0,
"data": [
{"name": "larry"},
{"name": "curly"},
{"name": "moe"}
]
}
```
To extract `data` you'd define a `parse` method on the collection as follows, to return the array of data to be stored.
```javascript
var MyCollection = Collection.extend({
parse: function (response) {
return response.data;
}
});
```
If you're using `ampersand-rest-collection`'s `fetch()` method, the `parse` method will be called with the response by default. Also, the options object passed to `set()` gets passed through as a second argument to allow for conditional parsing logic.
### set `collection.set(models, [options])`

@@ -228,0 +255,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