Skip to content

Commit ed82324

Browse files
author
Steve Thompson
committed
Updated README more.
Also working on making sure npm does not install redundant copies of packages
1 parent 4df1732 commit ed82324

File tree

9 files changed

+67
-49
lines changed

9 files changed

+67
-49
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,10 @@ prepend(values: any[]): this
532532
forEach(iterationFunction): this
533533
// Behaves same as Array.forEach()
534534
// iterationFunction = function(currentValue, currentIndex?, entireArray?){...}
535+
536+
set(newArray): this
537+
// Changes value of this.data to newArray without breaking its memory reference.
538+
// So if there are copies of this.data, the copies will be updated as well.
535539
536540
protected _createGetterAndOrSetterForEach(
537541
propertyNames: string[],
@@ -556,17 +560,18 @@ runMethod_and_returnThis(
556560

557561
```
558562
// changing the array content:
559-
arr.data = [1,2,3,4,5,6,7];
563+
arr.data = [{prop1: 'yes', prop2: 'no'}, {prop1: 'no', prop2: 'yes'}];
560564
```
561565

562566
## Performance
563567

564568
PublicArray has a large number of dependencies. You should keep this in mind when optimizing
565-
the performance of your app. If your code only uses one property of PublicArray, like for
566-
instance `.replace`, you will get a slight performance boost if you just use an instance of
567-
PublicArrayReplacer instead:
569+
the performance of your app. For example, say your code only uses PublicArray's `.replace` property
570+
and nothing else. Since `.replace` is an instance of PublicArrayReplacer, you will get a slight
571+
performance boost if you just instantiate PublicArrayReplacer instead of PublicArray:
568572
```
569-
let replace = new PublicArrayReplacer(arr);
573+
let replace = new PublicArrayReplacer(array);
574+
replace.adjacentAt(2, ['just', 'an', 'example']);
570575
```
571576
## Inheritance Chain
572577

dist/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PublicArray } from './privy/PublicArray';
1+
import { PublicArray } from './privy/PublicArray_previous';
22

33

44
export declare function getPublicArray(array?: any[]): PublicArray;

dist/privy/PublicArray.d.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,17 @@ export declare class PublicArray extends PublicArrayContent {
3737
private _sort;
3838

3939

40-
/***************
41-
Public Properties:
40+
// Public Properties:
4241

43-
readonly copy: PublicArray; // independent copy of this instance.
44-
readonly filter: PublicArrayFilter;
45-
readonly getConverted: PublicArrayGetterConverter;
46-
readonly get: PublicArrayGetter;
47-
readonly getAndRemove: PublicArrayGetterRemover;
48-
readonly insert: PublicArrayInserter;
49-
readonly remove: PublicArrayRemover;
50-
readonly replace: PublicArrayReplacer;
51-
readonly sort: PublicArraySorter;
52-
***************/
42+
readonly copy: PublicArray; // independent copy of this instance.
43+
readonly filter: PublicArrayFilter;
44+
readonly getConverted: PublicArrayGetterConverter;
45+
readonly get: PublicArrayGetter;
46+
readonly getAndRemove: PublicArrayGetterRemover;
47+
readonly insert: PublicArrayInserter;
48+
readonly remove: PublicArrayRemover;
49+
readonly replace: PublicArrayReplacer;
50+
readonly sort: PublicArraySorter;
5351

5452

5553
constructor(
@@ -69,14 +67,17 @@ export declare class PublicArray extends PublicArrayContent {
6967
);
7068

7169

72-
readonly copy: PublicArray;
73-
74-
7570
append(values: any[]): this;
7671

7772

7873
prepend(values: any[]): this;
7974

8075

81-
forEach(iterationFunction: any): this;
76+
forEach(
77+
iterationFunction: (currentValue: any, currentIndex?: number, entireArray?: any[]) => any
78+
): this;
79+
80+
81+
set(newArray: any[]): this;
82+
8283
}

dist/privy/PublicArray.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var __extends = (this && this.__extends) || (function () {
1414
})();
1515
Object.defineProperty(exports, "__esModule", { value: true });
1616
var array_append_prepend_1 = require("@writetome51/array-append-prepend");
17+
var set_array_1 = require("@writetome51/set-array");
1718
var di_factory_1 = require("@writetome51/di-factory");
1819
var public_array_content_1 = require("@writetome51/public-array-content");
1920
/**************
@@ -32,19 +33,6 @@ var public_array_content_1 = require("@writetome51/public-array-content");
3233
*************/
3334
var PublicArray = /** @class */ (function (_super) {
3435
__extends(PublicArray, _super);
35-
/***************
36-
Public Properties:
37-
38-
readonly copy: PublicArray; // independent copy of this instance.
39-
readonly filter: PublicArrayFilter;
40-
readonly getConverted: PublicArrayGetterConverter;
41-
readonly get: PublicArrayGetter;
42-
readonly getAndRemove: PublicArrayGetterRemover;
43-
readonly insert: PublicArrayInserter;
44-
readonly remove: PublicArrayRemover;
45-
readonly replace: PublicArrayReplacer;
46-
readonly sort: PublicArraySorter;
47-
***************/
4836
function PublicArray(
4937
// begin injected dependencies...
5038
_filter, _getConverted, _get, _getAndRemove, _insert, _remove, _replace, _sort,
@@ -89,11 +77,13 @@ var PublicArray = /** @class */ (function (_super) {
8977
PublicArray.prototype.prepend = function (values) {
9078
return this.returnThis_after(array_append_prepend_1.prepend(values, this.data));
9179
};
92-
// this.forEach(iterationFunction)
93-
// iterationFunction = function(currentItem, currentIndex?, entireArray?){...}
9480
PublicArray.prototype.forEach = function (iterationFunction) {
9581
return this.returnThis_after(this.data.forEach(iterationFunction));
9682
};
83+
// Use this for changing value of this.data without breaking its memory reference.
84+
PublicArray.prototype.set = function (newArray) {
85+
return this.returnThis_after(set_array_1.setArray(this.data, newArray));
86+
};
9787
return PublicArray;
9888
}(public_array_content_1.PublicArrayContent));
9989
exports.PublicArray = PublicArray;

dist/tests.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
export {};
2+
/****************
3+
4+
5+
let otherArr = arr.data;
6+
7+
otherArr.length = 0;
8+
9+
console.log(otherArr);
10+
11+
console.log(arr.data);
12+
*************/
213
/************
314
arr.remove.allAfterFirst(6);
415
arr.remove.allBeforeFirst(3);

dist/tests.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ var index_1 = require("./index");
44
console.log('hello');
55
//let arr = new PublicArrayReplacer([1, 2, 3, 4, 5, 6, 7, 8, 9]);
66
var arr = index_1.getPublicArray([1, 2, 3, 4, 5, 6, 7, 8, 9]);
7-
console.log(arr.remove.byIndex(0).byIndexes([1, 3, 5]).adjacentAt(1, 2));
7+
console.log(arr.remove.byIndex(0).byIndexes([1, 3, 5]).adjacentAt(1, 2)); // [2, 8, 9]
88
var arrCopy = arr.copy;
9-
console.log(arrCopy);
9+
arrCopy.data = [1, 2];
10+
console.log(arrCopy.data);
11+
console.log(arr.data);
1012
/****************
1113
1214

lib/privy/PublicArray.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { append, prepend } from '@writetome51/array-append-prepend';
2+
import { setArray } from '@writetome51/set-array';
23
import { DIFactory } from '@writetome51/di-factory';
34
import { PublicArrayRemover } from '@writetome51/public-array-remover';
45
import { PublicArrayContent } from '@writetome51/public-array-content';
@@ -29,10 +30,10 @@ import { PublicArrayFilter } from '@writetome51/public-array-filter';
2930

3031
export class PublicArray extends PublicArrayContent {
3132

32-
/***************
33-
Public Properties:
3433

35-
readonly copy: PublicArray; // independent copy of this instance.
34+
//Public Properties:
35+
36+
//readonly copy: PublicArray; // independent copy of this instance.
3637
readonly filter: PublicArrayFilter;
3738
readonly getConverted: PublicArrayGetterConverter;
3839
readonly get: PublicArrayGetter;
@@ -41,7 +42,7 @@ export class PublicArray extends PublicArrayContent {
4142
readonly remove: PublicArrayRemover;
4243
readonly replace: PublicArrayReplacer;
4344
readonly sort: PublicArraySorter;
44-
***************/
45+
4546

4647

4748
constructor(
@@ -94,11 +95,16 @@ export class PublicArray extends PublicArrayContent {
9495
}
9596

9697

97-
// this.forEach(iterationFunction)
98-
// iterationFunction = function(currentItem, currentIndex?, entireArray?){...}
99-
forEach(iterationFunction): this {
98+
forEach(iterationFunction: (currentValue, currentIndex?, entireArray?) => any): this {
10099
return this.returnThis_after(this.data.forEach(iterationFunction));
101100
}
102101

103102

103+
// Use this for changing value of this.data without breaking its memory reference.
104+
set(newArray): this {
105+
return this.returnThis_after(setArray(this.data, newArray));
106+
}
107+
108+
104109
}
110+

lib/tests.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import { PublicArrayReplacer } from '@writetome51/public-array-replacer';
44
console.log('hello');
55
//let arr = new PublicArrayReplacer([1, 2, 3, 4, 5, 6, 7, 8, 9]);
66
let arr = getPublicArray([1, 2, 3, 4, 5, 6, 7, 8, 9]);
7-
console.log(arr.remove.byIndex(0).byIndexes([1,3,5]).adjacentAt(1, 2));
7+
console.log(arr.remove.byIndex(0).byIndexes([1,3,5]).adjacentAt(1, 2));// [2, 8, 9]
88
let arrCopy = arr.copy;
9-
console.log(arrCopy);
9+
arrCopy.data = [1,2];
10+
console.log(arrCopy.data);
11+
console.log(arr.data);
1012

1113
/****************
1214

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@writetome51/public-array-getter-remover": "~1.0.0",
4040
"@writetome51/public-array-filter": "~1.0.5",
4141
"@writetome51/array-append-prepend": "~1.0.3",
42-
"@writetome51/di-factory": "~1.0.0"
42+
"@writetome51/di-factory": "~1.0.0",
43+
"@writetome51/set-array": "~1.0.0"
4344
}
4445
}

0 commit comments

Comments
 (0)