Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. class CollectionManager {
  2. constructor(){
  3. this.collectionList = {};
  4. }
  5. initialize(collections){
  6. ...
  7. }
  8. populate(){
  9. var collectionObjs = Object.keys(this.collectionList).map(function(key){
  10. return collectionManager.collectionList[key];
  11. });
  12. return Promise.all(collectionObjs.map(function(collection){
  13. collection.populateVideos();
  14. }));
  15. }
  16. }
  17.  
  18. class Collection {
  19. constructor(data){
  20. this.collectionInfo = data;
  21. this.videoArray = [];
  22. }
  23. populateVideos(){
  24. var collectionKey = this.collectionInfo.COLLECTIONID;
  25. var vChannels = Object.keys(this.collectionInfo.channels);
  26. return Promise.all(vChannels.map(requestVideos))
  27. .then(function (results) {
  28. var videoIdArray = [];
  29. return videoIdArray = [].concat.apply([], results);
  30. }).then(function(arrVideoIds){
  31. var groups = [];
  32. for (var i = 0; i < arrVideoIds.length; i += 50) {
  33. groups.push(arrVideoIds.slice(i, i + 50));
  34. }
  35. return groups;
  36. }).then(function(chunkedArrVideoIds){
  37. return Promise.all(chunkedArrVideoIds.map(requestVideoData)).then(function (results) {
  38. var videoTileArray = [].concat.apply([], results);
  39. collectionManager.collectionList[collectionKey].videoArray = videoTileArray;
  40. return videoTileArray;
  41. });
  42. });
  43. }
  44. displayCollection(){
  45. console.log(this.collectionInfo.COLLECTIONID);
  46. console.log(collectionManager.collectionList);
  47. console.log(collectionManager.collectionList[1]);
  48. console.log(collectionManager.collectionList[1].videoArray);
  49.  
  50. collectionManager.populate().then(
  51. function(){
  52. collectionManager.displayCollections()
  53. }
  54. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement