ng-miam 4.6.3 → 4.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3054,9 +3054,19 @@
3054
3054
  _this.resource = RecipeLike;
3055
3055
  _this.type = 'recipe-likes';
3056
3056
  _this.activeRecipeLikes = new Map();
3057
+ _this.MAX_RECIPE_LIKES_BEFORE_CLEAN = 200;
3058
+ _this.cleanUnobservedLikesIfNecessary = new i0.EventEmitter();
3059
+ _this.isCleaning = new rxjs.BehaviorSubject(false);
3060
+ _this.subscriptions = [];
3057
3061
  _this.register();
3062
+ _this.subscriptions.push(_this.cleanUnobservedLikesIfNecessary.pipe(operators.tap(function (_) { return _this.isCleaning.next(true); }), operators.debounceTime(100)).subscribe(function (_) {
3063
+ _this.doCleanUnobservedLikesIfNecessary();
3064
+ }));
3058
3065
  return _this;
3059
3066
  }
3067
+ RecipeLikesService.prototype.ngOnDestroy = function () {
3068
+ this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
3069
+ };
3060
3070
  RecipeLikesService.prototype.getLike = function (recipeId) {
3061
3071
  this.addLikeToActivesIfNecessary(recipeId);
3062
3072
  return this.activeRecipeLikes.get(recipeId);
@@ -3094,15 +3104,53 @@
3094
3104
  this.activeRecipeLikes.delete(recipeId);
3095
3105
  }
3096
3106
  };
3107
+ RecipeLikesService.prototype.doCleanUnobservedLikesIfNecessary = function () {
3108
+ var e_1, _a;
3109
+ var _this = this;
3110
+ console.debug('[Miam] will check cleaning', this.activeRecipeLikes.size);
3111
+ if (this.activeRecipeLikes.size < this.MAX_RECIPE_LIKES_BEFORE_CLEAN) {
3112
+ this.isCleaning.next(false);
3113
+ return;
3114
+ }
3115
+ console.debug('[Miam] will clean unobserved recipes like');
3116
+ var keysToDelete = [];
3117
+ try {
3118
+ for (var _b = __values(this.activeRecipeLikes), _c = _b.next(); !_c.done; _c = _b.next()) {
3119
+ var _d = __read(_c.value, 2), recipeId = _d[0], activeLikes = _d[1];
3120
+ if (activeLikes && activeLikes.observers.length === 0) {
3121
+ keysToDelete.push(recipeId);
3122
+ }
3123
+ }
3124
+ }
3125
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3126
+ finally {
3127
+ try {
3128
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3129
+ }
3130
+ finally { if (e_1) throw e_1.error; }
3131
+ }
3132
+ keysToDelete.forEach(function (recipeId) { return _this.activeRecipeLikes.delete(recipeId); });
3133
+ this.isCleaning.next(false);
3134
+ };
3097
3135
  RecipeLikesService.prototype.addLikesToRecipes = function (recipes) {
3098
3136
  var _this = this;
3099
3137
  if (!this.userService.isLogged$.value) {
3100
3138
  return rxjs.of(null);
3101
3139
  }
3140
+ ;
3141
+ return this.isCleaning.asObservable().pipe(operators.skipWhile(function (isCleaning) { return isCleaning; }), operators.take(1), operators.switchMap(function (_) { return _this.afterCLeanAddLikesToRecipes(recipes); }));
3142
+ };
3143
+ RecipeLikesService.prototype.afterCLeanAddLikesToRecipes = function (recipes) {
3144
+ var _this = this;
3145
+ var recipeIds = recipes.map(function (r) { return r.id; }).filter(function (rid) { return !_this.activeRecipeLikes.has(rid); });
3146
+ if (recipeIds.length == 0) {
3147
+ return rxjs.of(null);
3148
+ }
3149
+ ;
3102
3150
  return this.all({
3103
3151
  page: { size: 20, number: 1 },
3104
3152
  remotefilter: {
3105
- recipe_id: recipes.map(function (r) { return r.id; }).join(),
3153
+ recipe_id: recipeIds.join(),
3106
3154
  is_past: 'true,false'
3107
3155
  }
3108
3156
  }).pipe(operators.skipWhile(function (resp) { return resp.is_loading; }), operators.tap(function (result) {
@@ -7843,7 +7891,7 @@
7843
7891
  };
7844
7892
  LikeButtonComponent.prototype.ngOnDestroy = function () {
7845
7893
  this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
7846
- this.recipeLikesService.removeLikeFromActivesIfNecessary(this.recipe.id);
7894
+ this.recipeLikesService.cleanUnobservedLikesIfNecessary.emit();
7847
7895
  };
7848
7896
  LikeButtonComponent.prototype.currentPath = function () { return ''; };
7849
7897
  LikeButtonComponent.prototype.initRecipeLike = function () {
@@ -12961,11 +13009,8 @@
12961
13009
  }
12962
13010
  });
12963
13011
  this.noMoreRecipes = results.length === 0;
12964
- // Get all recipe-likes before displaying
12965
- return this.recipeLikesService.addLikesToRecipes(results).pipe(operators.map(function () {
12966
- _this.retrievedRecipes.emit(_this.currentRecipes);
12967
- return _this.currentRecipes;
12968
- }));
13012
+ this.retrievedRecipes.emit(this.currentRecipes);
13013
+ return rxjs.of(this.currentRecipes);
12969
13014
  }
12970
13015
  else {
12971
13016
  // tslint:disable-next-line: no-console