|
1 | 1 | "use strict";
|
| 2 | +var __extends = (this && this.__extends) || (function () { |
| 3 | + var extendStatics = function (d, b) { |
| 4 | + extendStatics = Object.setPrototypeOf || |
| 5 | + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
| 6 | + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
| 7 | + return extendStatics(d, b); |
| 8 | + }; |
| 9 | + return function (d, b) { |
| 10 | + extendStatics(d, b); |
| 11 | + function __() { this.constructor = d; } |
| 12 | + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
| 13 | + }; |
| 14 | +})(); |
2 | 15 | Object.defineProperty(exports, "__esModule", { value: true });
|
| 16 | +var array_append_prepend_1 = require("@writetome51/array-append-prepend"); |
| 17 | +var set_array_1 = require("@writetome51/set-array"); |
3 | 18 | var di_factory_1 = require("@writetome51/di-factory");
|
4 |
| -var public_array_filter_1 = require("@writetome51/public-array-filter"); |
5 |
| -var public_array_getter_1 = require("@writetome51/public-array-getter"); |
6 |
| -var public_array_getter_converter_1 = require("@writetome51/public-array-getter-converter"); |
7 |
| -var public_array_getter_remover_1 = require("@writetome51/public-array-getter-remover"); |
8 |
| -var public_array_inserter_1 = require("@writetome51/public-array-inserter"); |
9 |
| -var public_array_remover_1 = require("@writetome51/public-array-remover"); |
10 |
| -var public_array_replacer_1 = require("@writetome51/public-array-replacer"); |
11 |
| -var public_array_sorter_1 = require("@writetome51/public-array-sorter"); |
12 |
| -var PublicArray_1 = require("./PublicArray"); |
13 |
| -di_factory_1.DIFactory.register({ |
14 |
| - class: PublicArray_1.PublicArray, |
15 |
| - dependencies: [ |
16 |
| - public_array_filter_1.PublicArrayFilter, public_array_getter_converter_1.PublicArrayGetterConverter, public_array_getter_1.PublicArrayGetter, |
17 |
| - public_array_getter_remover_1.PublicArrayGetterRemover, public_array_inserter_1.PublicArrayInserter, |
18 |
| - public_array_remover_1.PublicArrayRemover, public_array_replacer_1.PublicArrayReplacer, public_array_sorter_1.PublicArraySorter |
19 |
| - ] |
20 |
| -}); |
21 |
| -// This must be used to instantiate PublicArray: |
22 |
| -function getPublicArray(array) { |
23 |
| - if (array === void 0) { array = []; } |
24 |
| - return di_factory_1.DIFactory.getInstance(PublicArray_1.PublicArray, [array]); |
25 |
| -} |
26 |
| -exports.getPublicArray = getPublicArray; |
| 19 | +var public_array_content_1 = require("@writetome51/public-array-content"); |
| 20 | +/*********************** |
| 21 | + This class is for general array manipulation. It's called PublicArray because it |
| 22 | + contains an array in a public property: 'data' . |
| 23 | +
|
| 24 | + The main reason you would use this class is if you hate JavaScript's built-in Array |
| 25 | + methods, like .slice(), .splice(), .push(), and .shift(). This class has much clearer |
| 26 | + and expressive method names, and a lot more of them. |
| 27 | +
|
| 28 | + A few examples of usage: |
| 29 | +
|
| 30 | + let arr = getPublicArray([1,2,3,4,5,6]); |
| 31 | + arr.remove.tail(2); // arr.data is now [1,2,3,4] |
| 32 | + if (arr.notEmpty) arr.prepend([10]); // arr.data is now [10,1,2,3,4] |
| 33 | + **********************/ |
| 34 | +var PublicArray = /** @class */ (function (_super) { |
| 35 | + __extends(PublicArray, _super); |
| 36 | + function PublicArray(data // the actual array, represented by inherited property this.data |
| 37 | + ) { |
| 38 | + if (data === void 0) { data = []; } |
| 39 | + var _this = _super.call(this, data) || this; |
| 40 | + var dependencyClasses = [ |
| 41 | + { path: '@writetome51/public-array-filter', name: 'PublicArrayFilter' }, |
| 42 | + { path: '@writetome51/public-array-getter-converter', name: 'PublicArrayGetterConverter' }, |
| 43 | + { path: '@writetome51/public-array-getter', name: 'PublicArrayGetter' }, |
| 44 | + { path: '@writetome51/public-array-getter-remover', name: 'PublicArrayGetterRemover' }, |
| 45 | + { path: '@writetome51/public-array-inserter', name: 'PublicArrayInserter' }, |
| 46 | + { path: '@writetome51/public-array-remover', name: 'PublicArrayRemover' }, |
| 47 | + { path: '@writetome51/public-array-replacer', name: 'PublicArrayReplacer' }, |
| 48 | + { path: '@writetome51/public-array-sorter', name: 'PublicArraySorter' } |
| 49 | + ]; |
| 50 | + _this._createGetterAndOrSetterForEach( |
| 51 | + // each of these is a public property: |
| 52 | + ['filter', 'getConverted', 'get', 'getAndRemove', 'insert', |
| 53 | + 'remove', 'replace', 'sort'], { |
| 54 | + get_getterFunction: function (property, index) { |
| 55 | + return function () { |
| 56 | + // Lazy-Loading is used to instantiate these properties: |
| 57 | + if (!(_this["_" + property])) { // if property not set... |
| 58 | + var dependencyClass = dependencyClasses[index]; |
| 59 | + // @ts-ignore |
| 60 | + var modul = require(dependencyClass.path); |
| 61 | + _this["_" + property] = di_factory_1.DIFactory.getInstance(modul[dependencyClass.name]); |
| 62 | + } |
| 63 | + _this["_" + property].data = _this.data; |
| 64 | + return _this["_" + property]; |
| 65 | + }; |
| 66 | + } |
| 67 | + }); |
| 68 | + return _this; |
| 69 | + } |
| 70 | + Object.defineProperty(PublicArray.prototype, "copy", { |
| 71 | + // this.copy -- returns independent copy of 'this', not linked to 'this' in any way. |
| 72 | + get: function () { |
| 73 | + // @ts-ignore |
| 74 | + return di_factory_1.DIFactory.getInstance(PublicArray, [this.get.copy()]); |
| 75 | + }, |
| 76 | + enumerable: true, |
| 77 | + configurable: true |
| 78 | + }); |
| 79 | + PublicArray.prototype.append = function (values) { |
| 80 | + return this.returnThis_after(array_append_prepend_1.append(values, this.data)); |
| 81 | + }; |
| 82 | + PublicArray.prototype.prepend = function (values) { |
| 83 | + return this.returnThis_after(array_append_prepend_1.prepend(values, this.data)); |
| 84 | + }; |
| 85 | + PublicArray.prototype.forEach = function (iterationFunction) { |
| 86 | + return this.returnThis_after(this.data.forEach(iterationFunction)); |
| 87 | + }; |
| 88 | + // Use this to change the value of this.data without breaking its memory reference. |
| 89 | + PublicArray.prototype.set = function (newArray) { |
| 90 | + return this.returnThis_after(set_array_1.setArray(this.data, newArray)); |
| 91 | + }; |
| 92 | + return PublicArray; |
| 93 | +}(public_array_content_1.PublicArrayContent)); |
| 94 | +exports.PublicArray = PublicArray; |
0 commit comments