Skip to content

Commit ca32a5d

Browse files
committed
Improved DCI class
1 parent 54d9db1 commit ca32a5d

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

samples/dci/DCI.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ var Context = (function () {
33
}
44
Context.extend = //for plain JS version
55
function (callback) {
6+
//return type isn't really void; void is used because otherwise TS gives this error when running `new MyContext(...`:
7+
//"Call signatures used in a 'new' expression must have a 'void' return type."
68
return function () {
79
var args = [];
810
for (var _i = 0; _i < (arguments.length - 0); _i++) {
911
args[_i] = arguments[_i + 0];
1012
}
1113
var context = new callback();
14+
if (!context.bindRoles)
15+
throw new Error('bindRoles() method not found');
16+
1217
context.bindRoles.apply(callback, arguments);
1318
return context;
1419
};

samples/dci/DCI.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
export class Context
22
{
33
//for plain JS version
4-
static extend(callback): Function {
5-
return function(...args : any[]) {
4+
static extend(callback) {
5+
//return type isn't really void; void is used because otherwise TS gives this error when running `new MyContext(...`:
6+
//"Call signatures used in a 'new' expression must have a 'void' return type."
7+
8+
return function(...args : any[]): void {
69
var context = new callback();
10+
if (!context.bindRoles) throw new Error('bindRoles() method not found');
11+
712
context.bindRoles.apply(callback, arguments);
813
return context;
914
}

samples/dci/js/TransferMoney/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var TransferMoney = require('./TransferMoney');
44
var src = new Account(20);
55
var dst = new Account(10);
66

7-
//var ctx = TransferMoney(src, dst, 10);
87
var ctx = new TransferMoney(src, dst, 10);
98

109
ctx.execute();

samples/dci/js/TransferMoney/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@ import TransferMoney = require('./TransferMoney');
44
var src = new Account(20);
55
var dst = new Account(10);
66

7-
8-
//var ctx = new TransferMoney(src, dst, 10);
9-
10-
11-
var ctx = TransferMoney(src, dst, 10);
7+
var ctx = new TransferMoney(src, dst, 10);
128

139
ctx.execute();
1410

1511
//ctx.bindRoles(dst, src, 50);
1612
//ctx.execute();
1713

1814
console.log(src.getBalance());
19-
console.log(dst.getBalance());
15+
console.log(dst.getBalance());

0 commit comments

Comments
 (0)