Last active
          September 5, 2019 18:20 
        
      - 
      
 - 
        
Save matthewrobb/5d44e26d73f8ea02740721cf84c3c426 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
matthewrobb revised this gist
Sep 5, 2019 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,14 +9,14 @@ export class SelfPopulatingList extends ConsumableArray { let count = 0; const tick = ()=> { if (this.length < 10) { this.push({ id: count++ }); } setTimeout(tick, 1000); }; setTimeout(tick); } }  - 
        
matthewrobb revised this gist
Sep 5, 2019 . No changes.There are no files selected for viewing
 - 
        
matthewrobb revised this gist
Sep 5, 2019 . No changes.There are no files selected for viewing
 - 
        
matthewrobb created this gist
Sep 5, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ const { defineProperties, getOwnPropertyDescriptors } = Object; /** * A root Array-like "class" compatible with both es5 and es6 styles */ export function ArrayLike() { if (!(this instanceof ArrayLike)) { // "callable-constructor" why not? return new ArrayLike(...arguments); } Array.apply(this, arguments); } defineProperties( ArrayLike.prototype, getOwnPropertyDescriptors(Array.prototype) ); export default ArrayLike; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ import ArrayLike from "./array-like.mjs"; /** * Basic idea: iteration is consumption */ export class ConsumableArray extends ArrayLike { [Symbol.iterator]() { return this; } next() { return this; } get value() { return this.shift(); } get done() { return !this.length; } } export default ConsumableArray; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import ConsumableArray from "./consumable-array.mjs"; /** * Demonstration: Will maintain a list of 10 items */ export class SelfPopulatingList extends ConsumableArray { constructor() { super(...arguments); let count = 0; const tick = ()=> { if (this.length < 10) { this.push({ id: count++ }); } setTimeout(tick, 1000); }; setTimeout(tick); } }