UNPKG

1.3 kBJavaScriptView Raw
1const Animation = require("../animation");
2const Led = require("./led");
3const Collection = require("../mixins/collection");
4
5/**
6 * new Leds()
7 *
8 * Create an Array-like object instance of Leds
9 * @alias Led.Collection
10 * @constructor
11 * @return {Leds}
12 */
13
14class Leds extends Collection {
15 constructor(numsOrObjects) {
16 super(numsOrObjects);
17 }
18 get type() {
19 return Led;
20 }
21
22 /**
23 * Animation.normalize
24 *
25 * @param [number || object] keyFrames An array of step values or a keyFrame objects
26 */
27 [Animation.normalize](keyFrameSet) {
28 return keyFrameSet.map((keyFrames, index) => {
29 if (keyFrames !== null) {
30 return this[index][Animation.normalize](keyFrames);
31 }
32 return keyFrames;
33 });
34 }
35
36 /**
37 * Animation.render
38 *
39 * @position [number] array of values to set the leds to
40 */
41 [Animation.render](frames) {
42 return this.each((led, i) => led[Animation.render]([frames[i]]));
43 }
44}
45
46Collection.installMethodForwarding(
47 Leds.prototype, Led.prototype,
48 {
49 skip: [Animation.normalize, Animation.render]
50 }
51);
52
53Collection.installCallbackReconciliation(
54 Leds.prototype,
55 ["pulse", "fade", "fadeIn", "fadeOut", "blink"]
56);
57
58// Assign Leds Collection class as static "method" of Led.
59Led.Collection = Leds;
60
61module.exports = Leds;