-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding documentation for missing observe methods #79
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5b5a7c1
Added initial docs for `push`
Mattchewone 0a83eff
Added remaining array method documentation
Mattchewone 06368b9
Added links on missing docs to can-reflect docs which have the implem…
Mattchewone 409002f
Improve documentation after feedback
Mattchewone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this right? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
@property {Symbol} can-observe/can.defineInstanceKey @can.defineInstanceKey | ||
@parent can-observe/function | ||
|
||
@description See [can-reflect.defineInstanceKey @@can.defineInstanceKey] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
@property {Symbol} can-observe/can.offInstanceBoundChange @can.offInstanceBoundChange | ||
@parent can-observe/function | ||
|
||
@description See [can-reflect/observe.offInstanceBoundChange @@can.offInstanceBoundChange] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
@property {Symbol} can-observe/can.offInstancePatches @can.offInstancePatches | ||
@parent can-observe/function | ||
|
||
@description See [can-reflect/observe.offInstancePatches @@can.offInstancePatches] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
@property {Symbol} can-observe/can.onInstanceBoundChange @can.onInstanceBoundChange | ||
@parent can-observe/function | ||
|
||
@description See [can-reflect/observe.onInstanceBoundChange @@can.onInstanceBoundChange] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
@property {Symbol} can-observe/can.onInstancePatches @can.onInstancePatches | ||
@parent can-observe/function | ||
|
||
@description See [can-reflect/observe.onInstancePatches @@can.onInstancePatches] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
@property {Symbol} can-observe/can.offKeyValue @can.offKeyValue | ||
@parent can-observe/object | ||
|
||
@description See [can-reflect/observe.offKeyValue @@can.offKeyValue] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
@property {Symbol} can-observe/can.offPatches @can.offPatches | ||
@parent can-observe/object | ||
|
||
@description See [can-reflect/observe.offPatches @@can.offPatches] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
@property {Symbol} can-observe/can.isBound @can.isBound | ||
@parent can-observe/object | ||
|
||
@description See [can-reflect/observe.isBound @@can.isBound] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
@property {Symbol} can-observe/can.onKeyValue @can.onKeyValue | ||
@parent can-observe/object | ||
|
||
@description See [can-reflect/observe.onKeyValue @@can.onKeyValue] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
@property {Symbol} can-observe/can.onPatches @can.onPatches | ||
@parent can-observe/object | ||
|
||
@description See [can-reflect/observe.onPatches @@can.onPatches] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I tested this for all methods. Length get's fired as the items are removed and re-added which is what get's shown in the event.