UNPKG

nakedobjects.spa

Version:

Single Page Application client for a Naked Objects application.

45 lines 1.99 kB
import map from 'lodash/map'; import every from 'lodash/map'; var RecentItemsViewModel = (function () { function RecentItemsViewModel(viewModelFactory, context, urlManager, onPaneId) { var _this = this; this.viewModelFactory = viewModelFactory; this.context = context; this.urlManager = urlManager; this.onPaneId = onPaneId; this.clear = function () { _this.context.clearRecentlyViewed(); _this.recentItems = []; _this.urlManager.triggerPageReloadByFlippingReloadFlagInUrl(_this.onPaneId); }; this.recentlyViewed = this.context.getRecentlyViewed(); this.refreshItems(); } RecentItemsViewModel.prototype.refreshItems = function () { var _this = this; var items = map(this.recentlyViewed, function (o, i) { return ({ obj: o, link: o.updateSelfLinkWithTitle(), index: i }); }); this.recentItems = map(items, function (i) { return _this.viewModelFactory.recentItemViewModel(i.obj, i.link, _this.onPaneId, false, i.index); }); }; RecentItemsViewModel.prototype.itemsHaveChanged = function () { var currentRecentlyViewed = this.context.getRecentlyViewed(); var same = this.recentlyViewed.length === currentRecentlyViewed.length && every(this.recentlyViewed, function (v, i) { return v.id() === currentRecentlyViewed[i].id(); }); if (!same) { this.recentlyViewed = currentRecentlyViewed; } return !same; }; Object.defineProperty(RecentItemsViewModel.prototype, "items", { get: function () { if (this.itemsHaveChanged()) { this.refreshItems(); } return this.recentItems; }, enumerable: true, configurable: true }); return RecentItemsViewModel; }()); export { RecentItemsViewModel }; //# sourceMappingURL=recent-items-view-model.js.map