Skip to content
This repository has been archived by the owner on Jul 30, 2022. It is now read-only.

manvalls/rul

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Remotely Updated List Build Status Coverage Status

Rul provides an abstraction layer above any list-like object, making it possible to control several different lists with a single unified interface. This can be achieved by consuming a rul:

var Rul = require('rul'),
    rul = new Rul();

// ...

rul.consume(
  function onAdd(elem,index){ /***/ },
  function onRemove(index,ammount){ /***/ },
  function onMove(lowerIndex,higherIndex){ /***/ }
);

What follows is an example of modifying a rul:

rul.add(0);
rul.clear();
rul.append([1,2,3,4,5,6,7]);
rul.add(4);
rul.replace(rul.length - 1,3);
rul.remove(1,2);
rul.move(2,4);
rul.swap(1,3);

// final state:
// [1, 7, 6, 4, 5, 3]

Above methods are available on any Rul instance. Some accessor methods are available too:

rul.indexOf(elem);
rul.lastIndexOf(elem);
rul.get(index);

for(value of rul){
  //...
}

These methods will only work on consumable ruls. A rul can become non-consumable if it was initialized as volatile (true as the only argument of the constructor) and has recently been consumed. Volatile ruls exist purely for the sake of memory management: when they become non-consumable they behave as sinks of data, it's up to the consumers to decide what to do with it, but the rul itself won't retain said data.

About

An abstraction designed to control any kind of list-like object

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published