Cycle through an array to select only a particular index and a specified number of neighbours.
JavaScript Shell
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
History.md
Makefile
Readme.md
component.json
index.js

Readme.md

cycle

Cycle through an array to select only a particular index and a specified number of neighbours.

Installation

Install with component(1):

$ component install bmcmahen/cycle

API

new Cycle(nodes, neighbours, options)

Neighbours specifies the number of neighbours to show, before and after the current index. options allows you to specify if you want to unload previously loaded, non-neighbouring nodes.

.show(i)

Specify the current index among the nodes in the array.

Example

var Cycle = require('cycle');
var arr = ['ben', 'kit', 'bacon', 'potato', 'fish', 'monster', 'word'];
var cycle = new Cycle(arr, 1, { unload: true });

cycle.on('enter', function(i, node){
  console.log('enter', i, node);
});

cycle.on('exit', function(i, node){
  console.log('exit', i, node);
});

var start = 0;
setInterval(function(){
  cycle.show(start);
  start++;
}, 5000);

License

MIT