ReactiveArray for Meteor
Table of contents
Introduction
The ReactiveArray package introduces a reactive version of the JavaScript Array object.
Installation
$ meteor add jagi:reactive-array
Usage
All methods are reactive. Values are stored in the original form, so you can also store functions and objects with functions. Objects are stored as references.
1var array = new ReactiveArray(); 2 3array.get(1); // Returns a value at index 1. 4array.get(); // Returns all values. 5 6array.length(); // Returns array length. 7 8array.slice(1, -1); // Slices a chunk of array. 9 10array.set(0, 'value'); // Insert a value at index 0. 11array.set([ // Replace current values with new ones. 12 'value1', 13 'value2', 14 'value3' 15]); 16 17// Pushes a value at the end and returns a new array length. 18array.push('value4'); 19// Pops a value from the end and returns it. 20array.pop(); 21 22// Pushes a value at the beginning and returns a new array length. 23array.unshift('value0'); 24// Pops a value from the beginning and returns it. 25array.shift();
More methods to come soon.