Skip to content
This repository has been archived by the owner on Sep 20, 2018. It is now read-only.

Commit

Permalink
[added] end() method for exiting chains
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Mar 10, 2016
1 parent 4cbe0a8 commit 05cd431
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,18 @@ $(<MyComponent/>).render()
.find('.foo')
```

##### `$.fn.end() => Collection`

Exits a chain, by returning the previous collection

```js
$(<MyComponent/>).render()
.find('ul')
.single()
.end()
.find('div')
```

##### `$.fn.each(Function iteratorFn)`

An analog to `Array.prototype.forEach`; iterates over the collection calling the `iteratorFn`
Expand Down
3 changes: 2 additions & 1 deletion src/QueryCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export default function createCollection(ctor) {
}

this._isQueryCollection = true
this.root = lastCollection || this
this.prevObject = lastCollection
this.root = lastCollection ? lastCollection.root : this

attachElementsToCollection(this, elements)

Expand Down
4 changes: 4 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ let common = {
return this;
},

end() {
return this.prevObject || this;
},

tap(fn) {
fn.call(this, this)
return this
Expand Down

0 comments on commit 05cd431

Please sign in to comment.