Skip to content

Commit 9f4f2df

Browse files
committed
added index Generation; fixed some bugs
1 parent 248838e commit 9f4f2df

File tree

7 files changed

+53
-15
lines changed

7 files changed

+53
-15
lines changed

dev/Helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace Linq4JS {
2-
export class Helper implements Helper {
2+
export class Helper {
33
static ConvertStringFunction: Function = function (functionString: string): Function {
44

55
if (functionString.length == 0) {

dev/IArray.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
UpdateRange(objects: Array<T>, primaryKeySelector?: any): Array<T>;
1010
Remove(object: T, primaryKeySelector?: any): Array<T>;
1111
RemoveRange(objects: Array<T>, primaryKeySelector?: any): Array<T>;
12-
Add(object: T): Array<T>;
12+
Add(object: T, generateId?: boolean): Array<T>;
1313
AddRange(objects: Array<T>): Array<T>;
1414
Insert(object: T, index: number): Array<T>;
1515
Where(filter: any): Array<T>;

dev/Modules/Add.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1-
Array.prototype.Add = function<T> (object: T): Array<T> {
1+
Array.prototype.Add = function<T> (object: T, generateId?: boolean): Array<T> {
22
let that: Array<T> = this;
33

44
if (object != null) {
5+
6+
if (generateId == true) {
7+
let newIndex: number;
8+
9+
let last: T = that.LastOrDefault();
10+
if(last != null){
11+
12+
newIndex = last["_Id"] != null ? last["_Id"] : 1;
13+
14+
while(that.Any(function(x){
15+
return x["_Id"] == newIndex;
16+
})){
17+
newIndex++;
18+
}
19+
20+
object["_Id"] = newIndex;
21+
}
22+
else{
23+
object["_Id"] = 1;
24+
}
25+
}
26+
527
that.push(object);
628
}
729

dev/OrderEntry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace Linq4JS {
2-
export class OrderEntry implements OrderEntry{
2+
export class OrderEntry{
33
test: string;
44
Direction: OrderDirection;
55
ValueSelector: Function;

dist/Linq4JS.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ declare namespace Linq4JS {
55
}
66
}
77
declare namespace Linq4JS {
8-
class Helper implements Helper {
8+
class Helper {
99
static ConvertStringFunction: Function;
1010
static ConvertFunction: Function;
1111
static OrderCompareFunction: Function;
@@ -21,7 +21,7 @@ interface Array<T> {
2121
UpdateRange(objects: Array<T>, primaryKeySelector?: any): Array<T>;
2222
Remove(object: T, primaryKeySelector?: any): Array<T>;
2323
RemoveRange(objects: Array<T>, primaryKeySelector?: any): Array<T>;
24-
Add(object: T): Array<T>;
24+
Add(object: T, generateId?: boolean): Array<T>;
2525
AddRange(objects: Array<T>): Array<T>;
2626
Insert(object: T, index: number): Array<T>;
2727
Where(filter: any): Array<T>;
@@ -43,7 +43,7 @@ interface Array<T> {
4343
Distinct(valueSelector: any, takelast?: boolean): Array<T>;
4444
}
4545
declare namespace Linq4JS {
46-
class OrderEntry implements OrderEntry {
46+
class OrderEntry {
4747
test: string;
4848
Direction: OrderDirection;
4949
ValueSelector: Function;

dist/Linq4JS.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,25 @@ var Linq4JS;
103103
OrderDirection[OrderDirection["Descending"] = 1] = "Descending";
104104
})(OrderDirection = Linq4JS.OrderDirection || (Linq4JS.OrderDirection = {}));
105105
})(Linq4JS || (Linq4JS = {}));
106-
Array.prototype.Add = function (object) {
106+
Array.prototype.Add = function (object, generateId) {
107107
var that = this;
108108
if (object != null) {
109+
if (generateId == true) {
110+
var newIndex_1;
111+
var last = that.LastOrDefault();
112+
if (last != null) {
113+
newIndex_1 = last["_Id"] != null ? last["_Id"] : 1;
114+
while (that.Any(function (x) {
115+
return x["_Id"] == newIndex_1;
116+
})) {
117+
newIndex_1++;
118+
}
119+
object["_Id"] = newIndex_1;
120+
}
121+
else {
122+
object["_Id"] = 1;
123+
}
124+
}
109125
that.push(object);
110126
}
111127
return that;

gulpfile.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ gulp.task("testts", function () {
2929
.pipe(gulp.dest("test"));
3030
});
3131

32-
gulp.task("typescriptRelease", function () {
32+
gulp.task("typescript", function () {
3333
var tsResult = gulp.src("dev/**/*.ts")
3434
.pipe(typescript({
3535
declaration: true,
@@ -42,7 +42,7 @@ gulp.task("typescriptRelease", function () {
4242
]);
4343
});
4444

45-
gulp.task("minifyJS", ["typescriptRelease"], function () {
45+
gulp.task("minifyJS", ["typescript"], function () {
4646
return gulp.src(["dist/**/*.js", "!dist/**/*.min.js"])
4747
.pipe(minify({
4848
ext: {
@@ -59,26 +59,26 @@ gulp.task("minifyJS", ["typescriptRelease"], function () {
5959
gulp.task("browsersync", function () {
6060
browsersync.init({
6161
proxy: {
62-
target: "localhost:15222",
62+
target: "localhost:15666",
6363
ws: true
6464
},
6565
ui: {
66-
port: 15224
66+
port: 15668
6767
},
68-
port: 15223,
68+
port: 15667,
6969
open: false,
7070
notify: false
7171
});
7272
});
7373

7474
gulp.task("server", ["browsersync"], function () {
7575
connect.server({
76-
port: 15222
76+
port: 15666
7777
});
7878

7979
gulp.watch("demo/**/*.ts", ["demots"]);
8080
gulp.watch("test/**/*.ts", ["testts"]);
81-
gulp.watch("js/**/*.ts", ["typescript"]);
81+
gulp.watch("dev/**/*.ts", ["typescript"]);
8282

8383
gulp.watch("**/*.html").on("change", browsersync.reload);
8484
gulp.watch("dist/**/*.js").on("change", browsersync.reload);

0 commit comments

Comments
 (0)