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

can-list

Package Overview
Dependencies
Maintainers
3
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-list - npm Package Compare versions

Comparing version 3.0.0-pre.4 to 3.0.0-pre.5

doc/GREADME.md

22

package.json
{
"name": "can-list",
"version": "3.0.0-pre.4",
"version": "3.0.0-pre.5",
"description": "Observable lists",

@@ -22,3 +22,3 @@ "homepage": "http://canjs.com",

"build": "node build.js",
"document": "documentjs",
"document": "bit-docs",
"develop": "done-serve --static --develop --port 8080",

@@ -57,3 +57,3 @@ "release:pre": "npm version prerelease && npm publish"

"devDependencies": {
"documentjs": "^0.4.2",
"bit-docs": "0.0.6",
"jshint": "^2.9.1",

@@ -72,3 +72,19 @@ "cssify": "^1.0.2",

"url": "git://github.com/canjs/can-list.git"
},
"bit-docs": {
"dependencies": {
"bit-docs-glob-finder": "^0.0.5",
"bit-docs-dev": "^0.0.3",
"bit-docs-js": "^0.0.3",
"bit-docs-generate-readme": "^0.0.8"
},
"glob": {
"pattern": "**/*.{js,md}",
"ignore": "node_modules/**/*"
},
"readme": {
"apis": "./docs/apis.json"
},
"parent": "can-list"
}
}

@@ -7,51 +7,249 @@ # can-list

## Usage
### ES6 use
- <code>[__can-list__ ](#can-list-)</code>
- <code>[new List([array])](#new-listarray)</code>
- <code>[new List(deferred)](#new-listdeferred)</code>
- <code>[List.extend([name,] [staticProperties,] instanceProperties)](#listextendname-staticproperties-instanceproperties)</code>
- <code>[Map can-map](#map-can-map)</code>
- <code>[list.attr()](#listattr)</code>
- <code>[list.attr(index)](#listattrindex)</code>
- <code>[list.attr(index, value)](#listattrindex-value)</code>
- <code>[list.attr(elements[, replaceCompletely])](#listattrelements-replacecompletely)</code>
- <code>[list.filter(filterFunc, context)](#listfilterfilterfunc-context)</code>
- <code>[list.splice(index[, howMany[, ...newElements]])](#listspliceindex-howmany-newelements)</code>
- <code>[list.each( callback(item, index) )](#listeach-callbackitem-index-)</code>
- <code>[list.reverse()](#listreverse)</code>
- <code>[list.map( callback(item, index, listReference), context )](#listmap-callbackitem-index-listreference-context-)</code>
With StealJS, you can import this module directly in a template that is autorendered:
## API
## <code>__can-list__ </code>
### <code>new List([array])</code>
Create an observable array-like object.
1. __array__ <code>{Array}</code>:
Items to seed the List with.
- __returns__ <code>{[can-list](#new-listarray)}</code>:
An instance of `List` with the elements from _array_.
### <code>new List(deferred)</code>
1. __deferred__ <code>{can.Deferred}</code>:
A deferred that resolves to an
array. When the deferred resolves, its values will be added to the list.
- __returns__ <code>{[can-list](#new-listarray)}</code>:
An initially empty `List`.
#### <code>List.extend([name,] [staticProperties,] instanceProperties)</code>
Creates a new extended constructor function. Learn more at [can.Construct.extend].
```js
import plugin from 'can-list';
var MyList = List.extend({}, {
// silly unnecessary method
count: function(){
return this.attr('length');
}
});
var list = new MyList([{}, {}]);
console.log(list.count()); // -> 2
```
### CommonJS use
Use `require` to load `can-list` and everything else
needed to create a template that uses `can-list`:
1. __name__ <code>{String}</code>:
If provided, adds the extened List constructor function to the window at the given name.
1. __staticProperties__ <code>{Object}</code>:
Properties and methods directly on the constructor function. The most common property to set is [Map](#map-can-map).
1. __instanceProperties__ <code>{Object}</code>:
Properties and methods on instances of this list type.
#### Map `{can-map}`
Specify the Map type used to make objects added to this list observable.
##### <code>can-map</code>
When objects are added to a `List`, those objects are converted into can.Map instances. For example:
var list = new List();
list.push({name: "Justin"});
var map = list.attr(0);
map.attr("name") //-> "Justin"
By changing [Map](#map-can-map), you can specify a different type of Map instance to create. For example:
var User = Map.extend({
fullName: function(){
return this.attr("first")+" "+this.attr("last")
}
});
User.List = List.extend({
Map: User
}, {});
var list = new User.List();
list.push({first: "Justin", last: "Meyer"});
var user = list.attr(0);
user.fullName() //-> "Justin Meyer"
#### <code>list.attr()</code>
Gets an array of all the elements in this `List`.
- __returns__ <code>{Array}</code>:
An array with all the elements in this List.
#### <code>list.attr(index)</code>
Reads an element from this `List`.
1. __index__ <code>{Number}</code>:
The element to read.
- __returns__ <code>{*}</code>:
The value at _index_.
#### <code>list.attr(index, value)</code>
Assigns _value_ to the index _index_ on this `List`, expanding the list if necessary.
1. __index__ <code>{Number}</code>:
The element to set.
1. __value__ <code>{*}</code>:
The value to assign at _index_.
- __returns__ <code>{}</code>:
This list, for chaining.
#### <code>list.attr(elements[, replaceCompletely])</code>
Merges the members of _elements_ into this List, replacing each from the beginning in order. If _elements_ is longer than the current List, the current List will be expanded. If _elements_ is shorter than the current List, the extra existing members are not affected (unless _replaceCompletely_ is `true`). To remove elements without replacing them, use `[can-map::removeAttr removeAttr]`.
1. __elements__ <code>{Array}</code>:
An array of elements to merge in.
1. __replaceCompletely__ <code>{bool}</code>:
whether to completely replace the elements of List
If _replaceCompletely_ is `true` and _elements_ is shorter than the List, the existing extra members of the List will be removed.
- __returns__ <code>{}</code>:
This list, for chaining.
#### <code>list.filter(filterFunc, context)</code>
1. __filterFunc__ <code>{function(item, index, undefined)}</code>:
A function to call with each element of the list. Returning `false` will remove the index.
1. __context__ <code>{Object}</code>:
The object to use as `this` inside the callback.
#### <code>list.splice(index[, howMany[, ...newElements]])</code>
1. __index__ <code>{Number}</code>:
where to start removing or inserting elements
1. __howMany__ <code>{Number}</code>:
the number of elements to remove
If _howMany_ is not provided, `splice` will remove all elements from `index` to the end of the List.
1. __newElements__ <code>{*}</code>:
elements to insert into the List
- __returns__ <code>{Array}</code>:
the elements removed by `splice`
#### <code>list.each( callback(item, index) )</code>
`each` iterates through the List, calling a function
for each element.
```js
var plugin = require("can-list");
var list = new List([1, 2, 3]);
list.each(function(elem){
console.log(elem);
});
```
## AMD use
Configure the `can` and `jquery` paths and the `can-list` package:
1. __callback__ <code>{function(*, Number)}</code>:
the function to call for each element
The value and index of each element will be passed as the first and second
arguments, respectively, to the callback. If the callback returns false,
the loop will stop.
```html
<script src="require.js"></script>
<script>
require.config({
paths: {
"jquery": "node_modules/jquery/dist/jquery",
"can": "node_modules/canjs/dist/amd/can"
},
packages: [{
name: 'can-list',
location: 'node_modules/can-list/dist/amd',
main: 'lib/can-list'
}]
});
require(["main-amd"], function(){});
</script>
```
- __returns__ <code>{}</code>:
this List, for chaining
### Standalone use
#### <code>list.reverse()</code>
Load the `global` version of the plugin:
```html
<script src='./node_modules/can-list/dist/global/can-list.js'></script>
```
`reverse` reverses the elements of the List in place.
- __returns__ <code>{[can-list](#new-listarray)}</code>:
the List, for chaining
#### <code>list.map( callback(item, index, listReference), context )</code>
1. __callback__ <code>{function(*, Number, undefined)}</code>:
A function to call with each
element of the list.
1. __context__ <code>{Object}</code>:
An optional object to use as `this` inside the callback.
- __returns__ <code>{}</code>:
A new can.List instance.
## Contributing

@@ -58,0 +256,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