Skip to content

Commit 4253c85

Browse files
typescript without web worker - v4
1 parent cffebb0 commit 4253c85

File tree

6 files changed

+146
-33
lines changed

6 files changed

+146
-33
lines changed

typescript_without_worker/package-lock.json

Lines changed: 124 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript_without_worker/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
},
99
"dependencies": {
1010
"jquery": "^3.3.1",
11-
"jsstore": "^3.7.3"
11+
"jsstore": "^4.0.1"
1212
},
1313
"devDependencies": {
14+
"@types/jquery": "^3.5.5",
1415
"css-loader": "^0.28.11",
15-
"file-loader": "^1.1.11",
16+
"file-loader": "^6.2.0",
1617
"html-webpack-plugin": "^3.2.0",
1718
"ts-loader": "^4.1.0",
1819
"typescript": "^2.7.2",

typescript_without_worker/src/business/student_logic.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ export class StudentLogic {
1616
this.addStudent();
1717
});
1818
// edit button
19-
$('#divContainer').on('click', 'td .btn-edit', (el) => {
19+
$('#divContainer').on('click', 'td .btn-edit', (el:any) => {
2020
const id = $(el.target).parents('tr').attr('data-id');
2121
this.editStudent(Number(id));
2222
});
2323
// delete button
24-
$('#divContainer').on('click', 'td .btn-delete', (el) => {
24+
$('#divContainer').on('click', 'td .btn-delete', (el:any) => {
2525
const id = $(el.target).parents('tr').attr('data-id');
2626
this.deleteStudent(Number(id));
2727
});
2828

29-
$('#divContainer').on('click', 'td .btn-update', (el) => {
29+
$('#divContainer').on('click', 'td .btn-update', (el:any) => {
3030
const id = $(el.target).parents('tr').attr('data-id');
3131
this.updateStudent(Number(id));
3232
});
3333

34-
$('#divContainer').on('click', 'td .btn-add-cancel', (el) => {
34+
$('#divContainer').on('click', 'td .btn-add-cancel', (el: any) => {
3535
const row = $(el.target).parents('tr');
3636
row.find('input').val('');
3737
});
3838

39-
$('#divContainer').on('click', 'td .btn-update-cancel', (el) => {
39+
$('#divContainer').on('click', 'td .btn-update-cancel', () => {
4040
this.refreshStudentList();
4141
});
4242

@@ -57,7 +57,7 @@ export class StudentLogic {
5757
</tr>`;
5858
}
5959

60-
async deleteStudent(studentId) {
60+
async deleteStudent(studentId: number) {
6161

6262
try {
6363
const rowsDeleted = await this.service.deleteStudent(studentId);
@@ -71,7 +71,7 @@ export class StudentLogic {
7171
}
7272
}
7373

74-
async updateStudent(studentId) {
74+
async updateStudent(studentId: number) {
7575
const columns = $("#tblStudents tbody tr[data-id='" + studentId + "']").find('td');
7676
const updatedValue: Student = {
7777
name: columns[0].querySelector('input').value,
@@ -93,7 +93,7 @@ export class StudentLogic {
9393
}
9494
}
9595

96-
async addStudent() {
96+
async addStudent() {
9797
const columns = document.querySelectorAll('.tr-add td');
9898
const student: Student = {
9999
name: columns[0].querySelector('input').value,
@@ -114,7 +114,7 @@ export class StudentLogic {
114114
}
115115
}
116116

117-
async editStudent(studentId) {
117+
async editStudent(studentId: number) {
118118

119119
try {
120120
const students = await this.service.getStudent(studentId);

typescript_without_worker/src/storage_service/idb_helper.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as JsStoreWorker from "jsstore/dist/jsstore.worker.commonjs2";
2-
window['JsStoreWorker'] = JsStoreWorker;
3-
import * as JsStore from 'jsstore';
4-
import { ITable, DATA_TYPE, IDataBase } from "jsstore";
1+
import { ITable, DATA_TYPE, IDataBase, Connection } from "jsstore";
2+
import workerInjector from "jsstore/dist/worker_injector";
53

64
// This will ensure that we are using only one instance.
75
// Otherwise due to multiple instance multiple worker will be created.
8-
export const idbCon = new JsStore.Connection();
6+
export const idbCon = new Connection();
7+
idbCon.addPlugin(workerInjector);
8+
99
export const dbname = 'Demo';
1010

1111
const getDatabase = () => {

typescript_without_worker/src/storage_service/student_service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BaseService } from './base_service';
22
import { Student } from '../model/student';
33

44
export class StudentService extends BaseService {
5-
5+
66
getStudents() {
77
return this.connection.select<Student>({
88
from: 'Students'
@@ -34,7 +34,7 @@ export class StudentService extends BaseService {
3434
});
3535
}
3636

37-
updateStudent(studentId: number, value) {
37+
updateStudent(studentId: number, value: any) {
3838
return this.connection.update({
3939
in: 'Students',
4040
set: value,

typescript_without_worker/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"moduleResolution": "node",
1414
"outDir": "dist/out-tsc",
1515
"sourceMap": true,
16-
"target": "es5"
16+
"target": "es5",
17+
"noImplicitAny": true
1718
}
18-
}
19+
}

0 commit comments

Comments
 (0)