Skip to content
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 4 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions doc/array/pop.md
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.
25 changes: 25 additions & 0 deletions doc/array/push.md
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.
23 changes: 23 additions & 0 deletions doc/array/reverse.md
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right?

Copy link
Contributor Author

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.

24 changes: 24 additions & 0 deletions doc/array/shift.md
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.
34 changes: 34 additions & 0 deletions doc/array/sort.md
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right?

44 changes: 44 additions & 0 deletions doc/array/splice.md
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.
25 changes: 25 additions & 0 deletions doc/array/unshift.md
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.
2 changes: 2 additions & 0 deletions doc/function/defineInstanceKey.md
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]
2 changes: 2 additions & 0 deletions doc/function/offInstanceBoundChange.md
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]
2 changes: 2 additions & 0 deletions doc/function/offInstancePatches.md
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]
2 changes: 2 additions & 0 deletions doc/function/onInstanceBoundChange.md
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]
2 changes: 2 additions & 0 deletions doc/function/onInstancePatches.md
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]
2 changes: 2 additions & 0 deletions doc/object/offKeyValue.md
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]
2 changes: 2 additions & 0 deletions doc/object/offPatches.md
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]
2 changes: 2 additions & 0 deletions doc/object/symbols-isBound.md
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]
2 changes: 2 additions & 0 deletions doc/object/symbols-onKeyValue.md
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]
2 changes: 2 additions & 0 deletions doc/object/symbols-onPatches.md
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]