diff --git a/doc/array/pop.md b/doc/array/pop.md index f71d45e..0dc4a07 100644 --- a/doc/array/pop.md +++ b/doc/array/pop.md @@ -1,2 +1,24 @@ @property {function} can-observe/pop pop @parent can-observe/array + +@description Remove an element from the end of an observe array. +@signature `list.pop()` + + `pop` removes the last element from the array. + + ```js + import { observe } from "can/everything"; + + const names = new observe.Array(['Alice', 'Bob']); + + console.log(names.pop()); //-> ['Bob'] + ``` + @codepen + + @return {*} The element from the end of the Array + +@body + +## Events + +`pop` causes _length_ events to be fired. diff --git a/doc/array/push.md b/doc/array/push.md index 17ba0ee..ba80611 100644 --- a/doc/array/push.md +++ b/doc/array/push.md @@ -1,2 +1,27 @@ @property {function} can-observe/push push @parent can-observe/array + +@description Add elements to the end of an observe array. +@signature `list.push(...elements)` + + `push` adds elements onto the end of an observe array. + + ```js + import { observe } from "can/everything"; + + const names = new observe.Array(['Alice', 'Bob']); + names.push('Chris'); + + console.log(names); //-> ['Alice', 'Bob', 'Chris'] + ``` + @codepen + + @param {*} elements the elements to add to the Array + + @return {Number} the new length of the Array + +@body + +## Events + +`push` causes _length_ events to be fired. diff --git a/doc/array/reverse.md b/doc/array/reverse.md index 56c05b3..5cc02ef 100644 --- a/doc/array/reverse.md +++ b/doc/array/reverse.md @@ -1,2 +1,25 @@ @property {function} can-observe/reverse reverse @parent can-observe/array + +@description Reverses the order of the observe array. +@signature `list.reverse()` + + `reverse` reverses the order of the array in place. + + ```js + import { observe } from "can/everything"; + + const names = new observe.Array(['Alice', 'Bob', 'Chris']); + names.reverse(); + + console.log(names); //-> ['Chris', 'Bob', 'Alice'] + ``` + @codepen + + @return {can-observe.Array} The array with reverse ordered elements + +@body + +## Events + +`reverse` causes _length_ events to be fired. diff --git a/doc/array/shift.md b/doc/array/shift.md index 062b86a..c3bc187 100644 --- a/doc/array/shift.md +++ b/doc/array/shift.md @@ -1,2 +1,26 @@ @property {function} can-observe/shift shift @parent can-observe/array + +@description Removes the first element from an array. +@signature `list.shift()` + + `shift` removes an element from the front of an array. + + ```js + import { observe } from "can/everything"; + + const names = new observe.Array(['Alice', 'Bob', 'Chris']); + console.log(names.shift()); //-> 'Alice' + console.log(names.shift()); //-> 'Bob' + console.log(names.shift()); //-> 'Chris' + console.log(names.shift()); //-> undefined + ``` + @codepen + + @return {*} The element shifted off from the array, or `undefined` if the array is empty + +@body + +## Events + +`shift` causes _length_ events to be fired. diff --git a/doc/array/sort.md b/doc/array/sort.md index 0eeba7e..d6da5b6 100644 --- a/doc/array/sort.md +++ b/doc/array/sort.md @@ -1,2 +1,36 @@ @property {function} can-observe/sort sort @parent can-observe/array + +@description Sort the elements in an array. +@signature `list.sort([compareFunction])` + + `sort` sorts the elements in place and returns the sorted array. The API is the same as the native [sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) API. + + ```js + import { observe } from "can/everything"; + + const names = new observe.Array(['Chris', 'Alice', 'Bob']); + + names.sort((a, b) => { + if (a.name < b.name) { + return -1; + } else if (a.name > b.name) { + return 1; + } else { + return 0; + } + }); + + console.log(names); //-> ['Alice', 'Bob', 'Chris'] + ``` + @codepen + + @param {function(a, b)} compareFunction Specifies a function that defines the sort order. + + @return {can-observe.Array} The ordered array + +@body + +## Events + +`sort` causes _length_ events to be fired. diff --git a/doc/array/splice.md b/doc/array/splice.md index f1743b8..faa60c1 100644 --- a/doc/array/splice.md +++ b/doc/array/splice.md @@ -1,2 +1,46 @@ @property {function} can-observe/splice splice @parent can-observe/array + +@description Insert and remove elements from an observe array. +@signature `list.splice(index[, howMany[, ...newItems]])` + + `splice` inserts and removes elements from an observe array. + + ```js + import { observe } from "can/everything"; + + const names = new observe.Array(['Alice', 'Bob', 'Chris']); + console.log(names.splice(0, 1)); //-> ['Alice'] + + console.log(names); //-> ['Bob', 'Chris'] + ``` + @codepen + + @param {Number} index Where to start removing or inserting elements + + @param {Number} howMany The number of elements to remove, if _howMany_ is not provided `splice` will remove all elements from the `index` to the end of the array. + + @param {*} newItems Items to insert into the array + + @return {Array} The elements removed by the `splice`. + +@body + +## Use + +`splice` lets you remove and insert items into an observe array. +This example shows replacing an item at a given index: + +```js +import { observe } from "can/everything"; + +const names = new observe.Array(['Alice', 'Bob', 'Chris']); +console.log(names.splice(1, 1, 'Dave')); //-> ['Bob'] + +console.log(names); //-> ['Alice', 'Bob', 'Chris'] +``` +@codepen + +## Events + +`splice` causes _length_ events to be fired. diff --git a/doc/array/unshift.md b/doc/array/unshift.md index e8ffa87..abd9c9f 100644 --- a/doc/array/unshift.md +++ b/doc/array/unshift.md @@ -1,2 +1,27 @@ @property {function} can-observe/unshift unshift @parent can-observe/array + +@description Add elements to the start of an observe array. +@signature `list.unshift(...elements)` + + `unshift` adds elements onto the start of an observe array. + + ```js + import { observe } from "can/everything"; + + const names = new observe.Array(['Alice', 'Bob']); + names.unshift('Chris'); + + console.log(names); //-> ['Chris', 'Alice', 'Bob'] + ``` + @codepen + + @param {*} elements the elements to add to the Array + + @return {Number} the new length of the Array + +@body + +## Events + +`unshift` causes _length_ events to be fired. diff --git a/doc/function/defineInstanceKey.md b/doc/function/defineInstanceKey.md index a656688..dc1ab82 100644 --- a/doc/function/defineInstanceKey.md +++ b/doc/function/defineInstanceKey.md @@ -1,2 +1,4 @@ @property {Symbol} can-observe/can.defineInstanceKey @can.defineInstanceKey @parent can-observe/function + +@description See [can-reflect.defineInstanceKey @@can.defineInstanceKey] diff --git a/doc/function/offInstanceBoundChange.md b/doc/function/offInstanceBoundChange.md index 8e01bbe..927a516 100644 --- a/doc/function/offInstanceBoundChange.md +++ b/doc/function/offInstanceBoundChange.md @@ -1,2 +1,4 @@ @property {Symbol} can-observe/can.offInstanceBoundChange @can.offInstanceBoundChange @parent can-observe/function + +@description See [can-reflect/observe.offInstanceBoundChange @@can.offInstanceBoundChange] diff --git a/doc/function/offInstancePatches.md b/doc/function/offInstancePatches.md index d9a50ad..eb83777 100644 --- a/doc/function/offInstancePatches.md +++ b/doc/function/offInstancePatches.md @@ -1,2 +1,4 @@ @property {Symbol} can-observe/can.offInstancePatches @can.offInstancePatches @parent can-observe/function + +@description See [can-reflect/observe.offInstancePatches @@can.offInstancePatches] diff --git a/doc/function/onInstanceBoundChange.md b/doc/function/onInstanceBoundChange.md index e47888f..59a9dd1 100644 --- a/doc/function/onInstanceBoundChange.md +++ b/doc/function/onInstanceBoundChange.md @@ -1,2 +1,4 @@ @property {Symbol} can-observe/can.onInstanceBoundChange @can.onInstanceBoundChange @parent can-observe/function + +@description See [can-reflect/observe.onInstanceBoundChange @@can.onInstanceBoundChange] diff --git a/doc/function/onInstancePatches.md b/doc/function/onInstancePatches.md index bd434fd..5cd0c98 100644 --- a/doc/function/onInstancePatches.md +++ b/doc/function/onInstancePatches.md @@ -1,2 +1,4 @@ @property {Symbol} can-observe/can.onInstancePatches @can.onInstancePatches @parent can-observe/function + +@description See [can-reflect/observe.onInstancePatches @@can.onInstancePatches] diff --git a/doc/object/offKeyValue.md b/doc/object/offKeyValue.md index 5678ff3..840c7f1 100644 --- a/doc/object/offKeyValue.md +++ b/doc/object/offKeyValue.md @@ -1,2 +1,4 @@ @property {Symbol} can-observe/can.offKeyValue @can.offKeyValue @parent can-observe/object + +@description See [can-reflect/observe.offKeyValue @@can.offKeyValue] diff --git a/doc/object/offPatches.md b/doc/object/offPatches.md index c88c733..ebaad10 100644 --- a/doc/object/offPatches.md +++ b/doc/object/offPatches.md @@ -1,2 +1,4 @@ @property {Symbol} can-observe/can.offPatches @can.offPatches @parent can-observe/object + +@description See [can-reflect/observe.offPatches @@can.offPatches] diff --git a/doc/object/symbols-isBound.md b/doc/object/symbols-isBound.md index aa4ba5e..e808eaa 100644 --- a/doc/object/symbols-isBound.md +++ b/doc/object/symbols-isBound.md @@ -1,2 +1,4 @@ @property {Symbol} can-observe/can.isBound @can.isBound @parent can-observe/object + +@description See [can-reflect/observe.isBound @@can.isBound] diff --git a/doc/object/symbols-onKeyValue.md b/doc/object/symbols-onKeyValue.md index a4d4c32..7f19fdc 100644 --- a/doc/object/symbols-onKeyValue.md +++ b/doc/object/symbols-onKeyValue.md @@ -1,2 +1,4 @@ @property {Symbol} can-observe/can.onKeyValue @can.onKeyValue @parent can-observe/object + +@description See [can-reflect/observe.onKeyValue @@can.onKeyValue] diff --git a/doc/object/symbols-onPatches.md b/doc/object/symbols-onPatches.md index aafd27e..dd1f818 100644 --- a/doc/object/symbols-onPatches.md +++ b/doc/object/symbols-onPatches.md @@ -1,2 +1,4 @@ @property {Symbol} can-observe/can.onPatches @can.onPatches @parent can-observe/object + +@description See [can-reflect/observe.onPatches @@can.onPatches]