Skip to content
/ cycle Public

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

Notifications You must be signed in to change notification settings

bmcmahen/cycle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published