Skip to content

Commit

Permalink
Add tslib
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhduong committed Apr 24, 2018
1 parent eedd993 commit abbe3e0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 41 deletions.
76 changes: 42 additions & 34 deletions demo/index.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,57 @@
import { Queryable } from '../dist/out-tsc/index.js';
import { Queryable } from '../dist/index.js';

const queryable = new Queryable();
// let promiseApi = new Promise((resolve, reject) => {
// // skills: attack, stamia, speed, shoot
// console.log('get players...');
// setTimeout(() => {
// resolve([
// { name: 'Ronaldo', overall: 96, nationId: 1, skills: [96, 85, 87, 91] },
// { name: 'Messi', overall: 98, nationId: 2, skills: [97, 85, 91, 93] },
// { name: 'Mbappe', overall: 86, nationId: 3, skills: [89, 81, 95, 83] },
// { name: 'Matial', overall: 81, nationId: 3, skills: [81, 80, 89, 81] },
// { name: 'Salah', overall: 89, nationId: 4, skills: [88, 82, 97, 86] }
// ]);
// }, 1000);
// })

let promiseApi = new Promise((resolve, reject) => {
// skills: attack, stamia, speed, shoot
let nations = new Promise(resolve => {
console.log('get nations...');
setTimeout(() => {
console.log('...get data');
resolve([
{ name: 'Ronaldo', overall: 96, nationId: 1, skills: [96, 85, 87, 91] },
{ name: 'Messi', overall: 98, nationId: 2, skills: [97, 85, 91, 93] },
{ name: 'Mbappe', overall: 86, nationId: 3, skills: [89, 81, 95, 83] },
{ name: 'Salah', overall: 89, nationId: 4, skills: [88, 82, 97, 86] }
{ id: 1, name: 'Portugal', areaId: 1 },
{ id: 2, name: 'Argentina', areaId: 2 },
{ id: 3, name: 'France', areaId: 1 },
{ id: 4, name: 'Egypt', areaId: 3 }
]);
}, 1000);
}, 2000);
})

let nations = [
{ id: 1, name: 'Portugal', areaId: 1 },
{ id: 2, name: 'Argentina', areaId: 2 },
{ id: 3, name: 'France', areaId: 1 },
{ id: 4, name: 'Egypt', areaId: 3 }
]
let continents = new Promise(resolve => {
console.log('get continents...');
setTimeout(() => {
resolve([
{ id: 1, areaName: 'Euro' },
{ id: 2, areaName: 'South America' },
]);
}, 2300);
})

let continents = [
{ id: 1, areaName: 'Euro' },
{ id: 2, areaName: 'South America' },
]

function main() {
// Just query not execute query
console.time('querytime');
let query = queryable
.from(promiseApi)
.join(nations, (x, y) => x.nationId === y.id)
.leftJoin(continents, (o, z) => o.y.areaId === z.id)
.select(o => {
return {
playerName: o.x.name,
overall: o.x.overall,
nation: o.y.name,
area: o.areaName,
}
})
.groupBy(x => x.area)
.orderByDescending(x => x.key);
let query =
Queryable.from(nations)
.join(continents, (x, y) => x.areaId === y.id)
.groupBy(o => o.y.areaName)
.select(x => {
let _tmp = {};
return {
area: x.key,
total: Queryable.from(x.items).count()
}
})


console.timeEnd('querytime');

Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
"typedoc": "^0.11.1",
"typescript": "^2.8.1",
"webpack": "^4.6.0"
},
"dependencies": {
"tslib": "^1.9.0"
}
}
19 changes: 12 additions & 7 deletions src/demo/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Queryable } from "../implements/queryable";

let promiseApi = new Promise((resolve, reject) => {
// skills: attack, stamia, speed, shoot
console.log('get players...');
setTimeout(() => {
console.log('...get data');
resolve([
{ name: 'Ronaldo', overall: 96, nationId: 1, skills: [96, 85, 87, 91] },
{ name: 'Messi', overall: 98, nationId: 2, skills: [97, 85, 91, 93] },
Expand All @@ -15,23 +15,25 @@ let promiseApi = new Promise((resolve, reject) => {
})

let nations: Promise<{ id, name, areaId }[]> = new Promise(resolve => {
console.log('get nations...');
setTimeout(() => {
resolve([
{ id: 1, name: 'Portugal', areaId: 1 },
{ id: 2, name: 'Argentina', areaId: 2 },
{ id: 3, name: 'France', areaId: 1 },
{ id: 4, name: 'Egypt', areaId: 3 }
]);
}, 1000);
}, 2000);
})

let continents = new Promise<{ id, areaName }[]>(resolve => {
console.log('get continents...');
setTimeout(() => {
resolve([
{ id: 1, areaName: 'Euro' },
{ id: 2, areaName: 'South America' },
]);
}, 1000);
}, 2300);
})


Expand All @@ -42,12 +44,15 @@ function main() {
Queryable
.from(nations)
.join(continents, (x, y) => x.areaId === y.id)
.select(o => {
.groupBy(o => o.y.areaName)
.select(x => {
let _tmp = {};
return {
nation: o.x.name,
area: o.y.areaName
area: x.key,
total: Queryable.from(x.items).count()
}
});
})


console.timeEnd('querytime');

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"importHelpers": true,
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
Expand Down

0 comments on commit abbe3e0

Please sign in to comment.