ng-track-by
Version:
trackBy and trackById directives which provide TrackByFunction to ngForTrackBy
151 lines (139 loc) • 7.81 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('logical-not')) :
typeof define === 'function' && define.amd ? define('ng-track-by', ['exports', '@angular/common', '@angular/core', 'logical-not'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ng-track-by'] = {}, global.ng.common, global.ng.core, global['logical-not']));
}(this, (function (exports, i1, i0, logicalNot) { 'use strict';
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
function changeTrackBy(ngForOf, trackBy, property) {
ngForOf.ngForTrackBy = trackBy;
patch(ngForOf, trackBy, property);
}
function patch(ngForOf, trackBy, property) {
var differ = ngForOf._differ;
differ._trackByFn = trackBy;
var linkedRecordsMap = differ._linkedRecords.map;
differ.forEachItem(function (record) {
var trackById = record.item[property];
linkedRecordsMap.set(trackById, linkedRecordsMap.get(record.trackById));
linkedRecordsMap.delete(record.trackById);
record.trackById = record.item[property];
});
}
var markedKey = Symbol();
function marked(ngForOf) {
var marked = markedKey in ngForOf;
ngForOf[markedKey] = undefined;
return marked;
}
var trackById = function (_, item) {
return item.id;
};
var TrackByIdDirective = /** @class */ (function () {
function TrackByIdDirective(ngForOf) {
this.ngForOf = ngForOf;
}
TrackByIdDirective.prototype.ngOnInit = function () {
if (logicalNot.not(marked(this.ngForOf)))
changeTrackBy(this.ngForOf, trackById, "id");
};
return TrackByIdDirective;
}());
TrackByIdDirective.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0__namespace, type: TrackByIdDirective, deps: [{ token: i1__namespace.NgForOf }], target: i0__namespace.ɵɵFactoryTarget.Directive });
TrackByIdDirective.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.0", type: TrackByIdDirective, selector: "[trackById]", ngImport: i0__namespace });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0__namespace, type: TrackByIdDirective, decorators: [{
type: i0.Directive,
args: [{
selector: "[trackById]",
}]
}], ctorParameters: function () { return [{ type: i1__namespace.NgForOf }]; } });
var TrackByIdModule = /** @class */ (function () {
function TrackByIdModule() {
}
return TrackByIdModule;
}());
TrackByIdModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0__namespace, type: TrackByIdModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
TrackByIdModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0__namespace, type: TrackByIdModule, declarations: [TrackByIdDirective], imports: [i1.CommonModule], exports: [TrackByIdDirective] });
TrackByIdModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0__namespace, type: TrackByIdModule, imports: [[i1.CommonModule]] });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0__namespace, type: TrackByIdModule, decorators: [{
type: i0.NgModule,
args: [{
imports: [i1.CommonModule],
exports: [TrackByIdDirective],
declarations: [TrackByIdDirective],
}]
}] });
var TrackByDirective = /** @class */ (function () {
function TrackByDirective(ngForOf) {
this.ngForOf = ngForOf;
}
TrackByDirective.prototype.ngOnInit = function () {
if (logicalNot.not(marked(this.ngForOf)))
changeTrackBy(this.ngForOf, this.createTrackByFn(), this.trackBy);
};
TrackByDirective.prototype.createTrackByFn = function () {
var key = this.trackBy;
return function (_, item) {
return item[key];
};
};
return TrackByDirective;
}());
TrackByDirective.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0__namespace, type: TrackByDirective, deps: [{ token: i1__namespace.NgForOf }], target: i0__namespace.ɵɵFactoryTarget.Directive });
TrackByDirective.ɵdir = i0__namespace.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.0", type: TrackByDirective, selector: "[trackBy]", inputs: { trackBy: "trackBy" }, ngImport: i0__namespace });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0__namespace, type: TrackByDirective, decorators: [{
type: i0.Directive,
args: [{
selector: "[trackBy]",
}]
}], ctorParameters: function () { return [{ type: i1__namespace.NgForOf }]; }, propDecorators: { trackBy: [{
type: i0.Input
}] } });
var TrackByModule = /** @class */ (function () {
function TrackByModule() {
}
return TrackByModule;
}());
TrackByModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0__namespace, type: TrackByModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
TrackByModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0__namespace, type: TrackByModule, declarations: [TrackByDirective], imports: [i1.CommonModule], exports: [TrackByDirective] });
TrackByModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0__namespace, type: TrackByModule, imports: [[i1.CommonModule]] });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.0", ngImport: i0__namespace, type: TrackByModule, decorators: [{
type: i0.NgModule,
args: [{
imports: [i1.CommonModule],
exports: [TrackByDirective],
declarations: [TrackByDirective],
}]
}] });
/*
* Public API Surface of ng-track-by
*/
/**
* Generated bundle index. Do not edit.
*/
exports.TrackByDirective = TrackByDirective;
exports.TrackByIdDirective = TrackByIdDirective;
exports.TrackByIdModule = TrackByIdModule;
exports.TrackByModule = TrackByModule;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ng-track-by.umd.js.map