Skip to content

Commit

Permalink
refactor: rename nextOf and previousOf to nextItem and previousItem
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenrui committed Nov 9, 2023
1 parent 049e353 commit c3dfe15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ <h3 class="font-bold font-mono">Multi Select:</h3>
:enter="selectedTags = selectedTags.add(selectedTag);
filteredTags = filteredTags.remove(selectedTag);
selectedTag = filteredTags.first"
:keyup.up="selectedTag = filteredTags.previousOf(selectedTag)"
:keyup.down="selectedTag = filteredTags.nextOf(selectedTag)"
:keyup.up="selectedTag = filteredTags.previousItem(selectedTag)"
:keyup.down="selectedTag = filteredTags.nextItem(selectedTag)"
/>

<div :clickout="filteredTags = []; selectedTag = null" :class="filteredTags.length ? '' : 'hidden'" class="bg-white rounded">
Expand Down Expand Up @@ -423,8 +423,8 @@ <h3 class="font-bold font-mono">Multi Select:</h3>
:enter=&quot;selectedTags = selectedTags.add(selectedTag);
filteredTags = filteredTags.remove(selectedTag);
selectedTag = filteredTags.first&quot;
:keyup.up=&quot;selectedTag = filteredTags.previousOf(selectedTag)&quot;
:keyup.down=&quot;selectedTag = filteredTags.nextOf(selectedTag)&quot;
:keyup.up=&quot;selectedTag = filteredTags.previousItem(selectedTag)&quot;
:keyup.down=&quot;selectedTag = filteredTags.nextItem(selectedTag)&quot;
/&gt;

&lt;div :clickout=&quot;filteredTags = []; selectedTag = null&quot; :class=&quot;filteredTags.length ? '' : 'hidden' &quot; class=&quot;bg-white rounded&quot;&gt;
Expand Down
4 changes: 2 additions & 2 deletions lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export default class MiniArray extends Array {
return this.at(-1);
}

nextOf(item) {
nextItem(item) {
const nextIndex = this.indexOf(item) + 1;
return nextIndex >= this.length ? this.first : this.at(nextIndex);
}

previousOf(item) {
previousItem(item) {
const previousIndex = this.indexOf(item) - 1;
return previousIndex < 0 ? this.last : this.at(previousIndex);
}
Expand Down
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ Here are the custom array methods which are available for you to use:
array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
array.remove('Tag 2') // returns ['Tag 1', 'Tag 3', 'Tag 4']
```
- `nextOf` - gets the next item in the array.
Usage: `array.nextOf('item')`
- `nextItem` - gets the next item in the array.
Usage: `array.nextItem('item')`
```js
array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
array.nextOf('Tag 2') // returns 'Tag 3'
array.nextItem('Tag 2') // returns 'Tag 3'
```
- `previousOf` - gets the next item in the array.
- `previousItem` - gets the next item in the array.
Usage: `array.previousOf('item')`
```js
array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
array.previousOf('Tag 2') // returns 'Tag 1'
array.previousItem('Tag 2') // returns 'Tag 1'
```
To trigger a re-render you need to update the variable:
Expand Down

0 comments on commit c3dfe15

Please sign in to comment.