|
4 | 4 |
|
5 | 5 | To setup MiniJS in your local machine, you can do the following:
|
6 | 6 |
|
7 |
| -1. Clone [repository](https://github.com/Group-One-Technology/minijs). |
| 7 | +1. Clone the [repository](https://github.com/Group-One-Technology/minijs). |
8 | 8 | 2. Run `npm install` to install dependencies.
|
9 |
| -3. Run `npm run build` to create a `dist` -> output for MiniJS. |
10 |
| -4. Run `npm run dev` to run demo page locally. |
11 |
| -5. Run `npm run build-watch` to run build when code changes. |
| 9 | +3. Run `npm run build` to create the `dist` folder -> output for MiniJS. |
| 10 | +4. Run `npm run dev` to run the demo page locally. |
| 11 | +5. Run `npm run build-watch` on another terminal to build the code whenever the Mini.js code changes. |
12 | 12 |
|
13 | 13 | ## The Idea
|
14 | 14 |
|
@@ -201,49 +201,72 @@ Here are the custom array methods which are available for you to use:
|
201 | 201 |
|
202 | 202 | - `first` - returns the first item in the array.
|
203 | 203 | Usage: `array.first`
|
| 204 | + |
204 | 205 | ```js
|
205 | 206 | array = ['Cherries', 'Chocolate', 'Blueberry', 'Vanilla']
|
206 |
| - array.last // returns 'Vanilla' |
| 207 | + array.first // returns 'Cherries' |
207 | 208 | ```
|
| 209 | + |
208 | 210 | - `last` - returns the last item in the array.
|
209 | 211 | Usage: `array.last`
|
| 212 | + |
210 | 213 | ```js
|
211 | 214 | array = ['Cherries', 'Chocolate', 'Blueberry', 'Vanilla']
|
212 |
| - array.first // returns 'Cherries' |
| 215 | + array.last // returns 'Vanilla' |
213 | 216 | ```
|
| 217 | + |
214 | 218 | - `search` - returns an array of items that match the query.
|
215 | 219 | Usage: `array.search('query')`
|
| 220 | + |
216 | 221 | ```js
|
217 | 222 | array = ['Cherries', 'Chocolate', 'Blueberry', 'Vanilla']
|
218 | 223 | array.search('c') // returns ['Cherries', 'Chocolate']
|
219 | 224 | ```
|
220 |
| -- `toggle` |
221 |
| - Usage: `array.toggle('item')` |
| 225 | + |
222 | 226 | - `add` - adds an item to the array if it doesn't exist.
|
223 | 227 | Usage: `array.add('item')`
|
| 228 | + |
224 | 229 | ```js
|
225 | 230 | array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
|
226 | 231 | array.add('Tag 5') // returns ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4', 'Tag 5']
|
227 | 232 | ```
|
| 233 | + |
228 | 234 | - `remove` - removes an item from the array if it exists.
|
229 | 235 | Usage: `array.remove('item')`
|
| 236 | + |
230 | 237 | ```js
|
231 | 238 | array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
|
232 | 239 | array.remove('Tag 2') // returns ['Tag 1', 'Tag 3', 'Tag 4']
|
233 | 240 | ```
|
234 |
| -- `nextItem` - gets the next item in the array. |
| 241 | + |
| 242 | +- `toggle` - removes / adds the item in the array |
| 243 | + Usage: `array.toggle('item')` |
| 244 | + |
| 245 | + ```js |
| 246 | + array = ['Cherries', 'Chocolate', 'Blueberry', 'Vanilla'] |
| 247 | + array.toggle('Cherries') // removes 'Cherries' |
| 248 | + // returns ['Chocolate', 'Blueberry', 'Vanilla'] |
| 249 | + |
| 250 | + array.toggle('Cherries') // re-adds 'Cherries' |
| 251 | + // returns ['Cherries', 'Chocolate', 'Blueberry', 'Vanilla'] |
| 252 | + ``` |
| 253 | + |
| 254 | +- `nextItem` - gets the next item based on the given item in the array. |
235 | 255 | Usage: `array.nextItem('item')`
|
236 | 256 | ```js
|
237 | 257 | array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
|
238 | 258 | array.nextItem('Tag 2') // returns 'Tag 3'
|
239 | 259 | ```
|
240 |
| -- `previousItem` - gets the next item in the array. |
| 260 | +- `previousItem` - gets the next item based on the given item in the array. |
241 | 261 | Usage: `array.previousOf('item')`
|
| 262 | + |
242 | 263 | ```js
|
243 | 264 | array = ['Tag 1', 'Tag 2', 'Tag 3', 'Tag 4']
|
244 | 265 | array.previousItem('Tag 2') // returns 'Tag 1'
|
245 | 266 | ```
|
246 | 267 |
|
| 268 | +#### Triggering Array Updates |
| 269 | + |
247 | 270 | To trigger a re-render you need to update the variable:
|
248 | 271 |
|
249 | 272 | ```js
|
|
0 commit comments