From 43c1aa9dca801653bf51714635345a47afe01ccc Mon Sep 17 00:00:00 2001 From: vspirin Date: Fri, 10 Jun 2016 17:10:31 +0300 Subject: [PATCH 1/4] add methods setAdapter/getAdapter & remove adapter from constructor params --- lib/command.d.ts | 2 +- lib/command.js | 4 +- lib/command.js.map | 2 +- lib/commands.d.ts | 4 +- lib/commands.js | 42 ++++++----- lib/commands.js.map | 2 +- lib/connect.d.ts | 38 +--------- lib/connect.js | 132 ++------------------------------- lib/connect.js.map | 2 +- lib/connect.ts | 14 ++-- lib/guaranteed_command.d.ts | 1 + lib/guaranteed_command.js | 4 + lib/guaranteed_command.js.map | 2 +- lib/guaranteed_commands.d.ts | 4 +- lib/guaranteed_commands.js | 27 +++---- lib/guaranteed_commands.js.map | 2 +- 16 files changed, 67 insertions(+), 215 deletions(-) diff --git a/lib/command.d.ts b/lib/command.d.ts index 6a7adc3..e5675fb 100644 --- a/lib/command.d.ts +++ b/lib/command.d.ts @@ -3,6 +3,6 @@ export declare class Command { promise: JQueryDeferred; constructor(msg: any); done(respond: any): void; - fail(): void; + fail(respond: any): void; private destroy(); } diff --git a/lib/command.js b/lib/command.js index 8408acd..7c56f4a 100644 --- a/lib/command.js +++ b/lib/command.js @@ -8,8 +8,8 @@ var Command = (function () { this.promise.resolve(respond); this.destroy(); }; - Command.prototype.fail = function () { - this.promise.reject(); + Command.prototype.fail = function (respond) { + this.promise.reject(respond); this.destroy(); }; Command.prototype.destroy = function () { diff --git a/lib/command.js.map b/lib/command.js.map index 2f1cc2b..452e87e 100644 --- a/lib/command.js.map +++ b/lib/command.js.map @@ -1 +1 @@ -{"version":3,"file":"command.js","sourceRoot":"","sources":["command.ts"],"names":[],"mappings":";AAAA;IAKI,iBAAY,GAAQ;QAChB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAEM,sBAAI,GAAX,UAAY,OAAY;QACpB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEM,sBAAI,GAAX;QACI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEO,yBAAO,GAAf;QACI,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IACL,cAAC;AAAD,CAAC,AAvBD,IAuBC;AAvBY,eAAO,UAuBnB,CAAA"} \ No newline at end of file +{"version":3,"file":"command.js","sourceRoot":"","sources":["command.ts"],"names":[],"mappings":";AAAA;IAKI,iBAAY,GAAQ;QAChB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAEM,sBAAI,GAAX,UAAY,OAAY;QACpB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEM,sBAAI,GAAX,UAAY,OAAY;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEO,yBAAO,GAAf;QACI,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IACL,cAAC;AAAD,CAAC,AAvBD,IAuBC;AAvBY,eAAO,UAuBnB,CAAA"} \ No newline at end of file diff --git a/lib/commands.d.ts b/lib/commands.d.ts index 2d5fd8c..1f1e3d6 100644 --- a/lib/commands.d.ts +++ b/lib/commands.d.ts @@ -4,8 +4,6 @@ export declare class Commands { private openCommands; constructor(params: any); create(msg: any): JQueryDeferred; - findAndResolve(msg: any, clientMsgId: string): boolean; fail(): void; - private find(clientMsgId); - private delete(command); + extract(clientMsgId: string): any; } diff --git a/lib/commands.js b/lib/commands.js index 6fd9bf8..4d04112 100644 --- a/lib/commands.js +++ b/lib/commands.js @@ -7,37 +7,39 @@ var Commands = (function () { this.openCommands = []; } Commands.prototype.create = function (msg) { + var openCommands = this.openCommands; var command = new command_1.Command(msg); - this.openCommands.push(command); + openCommands.push(command); if (this.state.isConnected()) { this.send(msg); } else { - command.fail(); + command.fail(undefined); + openCommands.splice(openCommands.indexOf(command), 1); } return command.promise; }; - Commands.prototype.findAndResolve = function (msg, clientMsgId) { - var command = this.find(clientMsgId); - if (command) { - this.delete(command); - command.done(msg); - return true; - } - }; Commands.prototype.fail = function () { - this.openCommands.forEach(function (command) { + var openCommands = this.openCommands; + var command; + for (var i = 0; i < openCommands.length; i += 1) { + command = openCommands.pop(); command.fail(); - }); - }; - Commands.prototype.find = function (clientMsgId) { - return this.openCommands.find(function (command) { - return command.msg.clientMsgId === clientMsgId; - }); + } }; - Commands.prototype.delete = function (command) { - var index = this.openCommands.indexOf(command); - this.openCommands.splice(index, 1); + Commands.prototype.extract = function (clientMsgId) { + var openCommands = this.openCommands; + var openCommandsLength = openCommands.length; + var command; + var index = 0; + while (index < openCommandsLength) { + var command = openCommands[index]; + if (command.msg.clientMsgId === clientMsgId) { + openCommands.splice(index, 1); + return command; + } + index += 1; + } }; return Commands; }()); diff --git a/lib/commands.js.map b/lib/commands.js.map index 0e57163..aa4bf88 100644 --- a/lib/commands.js.map +++ b/lib/commands.js.map @@ -1 +1 @@ -{"version":3,"file":"commands.js","sourceRoot":"","sources":["commands.ts"],"names":[],"mappings":";AAAA,wBAAsB,WAAW,CAAC,CAAA;AAGlC;IAMI,kBAAY,MAAW;QACnB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IAC3B,CAAC;IAEM,yBAAM,GAAb,UAAc,GAAQ;QAClB,IAAI,OAAO,GAAG,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AEM,0BAAO,GAAd,UAAe,WAAmB;QAC9B,IAAI,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QACrC,IAAI,kBAAkB,GAAG,YAAY,CAAC,MAAM,CAAC;QAC7C,IAAI,OAAO,CAAC;QACZ,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,OAAO,KAAK,GAAG,kBAAkB,EAAE,CAAC;YAChC,IAAI,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YAClC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC;gBAC1C,YAAY,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBAC9B,MAAM,CAAC,OAAO,CAAC;YACnB,CAAC;YACD,KAAK,IAAI,CAAC,CAAC;QACf,CAAC;IACL,CAAC;IAEL,eAAC;AAAD,CAAC,AApDD,IAoDC;AApDY,gBAAQ,WAoDpB,CAAA"} \ No newline at end of file diff --git a/lib/connect.d.ts b/lib/connect.d.ts index 01df6e5..21710a6 100644 --- a/lib/connect.d.ts +++ b/lib/connect.d.ts @@ -1,40 +1,5 @@ import { EventEmitter } from 'events'; -export declare class GuaranteedCommand { - private msg; - promise: JQueryDeferred; - constructor(msg: any); - done(msg: any): void; - fail(msg: any): void; - private destroy(); -} -export declare class GuaranteedCommands { - private state; - private send; - private openCommands; - constructor(params: any); - create(msg: any): JQueryDeferred; - resend(): void; - extract(clientMsgId: string): any; -} -export declare class Command { - private msg; - promise: JQueryDeferred; - constructor(msg: any); - done(respond: any): void; - fail(respond: any): void; - private destroy(); -} -export declare class Commands { - private state; - private send; - private openCommands; - constructor(params: any); - create(msg: any): JQueryDeferred; - fail(): void; - extract(clientMsgId: string): any; -} export interface IConnectionParams { - adapter: any; encodeDecode: any; protocol: any; } @@ -46,9 +11,10 @@ export declare class Connect extends EventEmitter { private guaranteedCommands; private commands; constructor(params: IConnectionParams); + getAdapter(): any; setAdapter(adapter: any): void; private initialization(); - start(): JQueryDeferred<{}>; + start(): JQueryPromise; private onData(data); private onOpen(); sendGuaranteedCommand(payloadType: any, params: any): JQueryDeferred; diff --git a/lib/connect.js b/lib/connect.js index 7b4609d..e9358d4 100644 --- a/lib/connect.js +++ b/lib/connect.js @@ -6,145 +6,29 @@ var __extends = (this && this.__extends) || function (d, b) { }; var events_1 = require('events'); var state_1 = require('./state'); -var GuaranteedCommand = (function () { - function GuaranteedCommand(msg) { - this.msg = msg; - this.promise = $.Deferred(); - } - GuaranteedCommand.prototype.done = function (msg) { - this.promise.resolve(msg); - this.destroy(); - }; - GuaranteedCommand.prototype.fail = function (msg) { - this.promise.reject(msg); - this.destroy(); - }; - GuaranteedCommand.prototype.destroy = function () { - delete this.msg; - }; - return GuaranteedCommand; -}()); -exports.GuaranteedCommand = GuaranteedCommand; -var GuaranteedCommands = (function () { - function GuaranteedCommands(params) { - this.state = params.state; - this.send = params.send; - this.openCommands = []; - } - GuaranteedCommands.prototype.create = function (msg) { - var command = new GuaranteedCommand(msg); - this.openCommands.push(command); - if (this.state.isConnected()) { - this.send(msg); - } - return command.promise; - }; - GuaranteedCommands.prototype.resend = function () { - this.openCommands - .map(function (command) { - return command.msg; - }) - .forEach(this.send); - }; - GuaranteedCommands.prototype.extract = function (clientMsgId) { - var openCommands = this.openCommands; - var openCommandsLength = openCommands.length; - var command; - var index = 0; - while (index < openCommandsLength) { - var command = openCommands[index]; - if (command.msg.clientMsgId === clientMsgId) { - openCommands.splice(index, 1); - return command; - } - index += 1; - } - }; - return GuaranteedCommands; -}()); -exports.GuaranteedCommands = GuaranteedCommands; -var Command = (function () { - function Command(msg) { - this.msg = msg; - this.promise = $.Deferred(); - } - Command.prototype.done = function (respond) { - this.promise.resolve(respond); - this.destroy(); - }; - Command.prototype.fail = function (respond) { - this.promise.reject(respond); - this.destroy(); - }; - Command.prototype.destroy = function () { - delete this.msg; - }; - return Command; -}()); -exports.Command = Command; -var Commands = (function () { - function Commands(params) { - this.state = params.state; - this.send = params.send; - this.openCommands = []; - } - Commands.prototype.create = function (msg) { - var openCommands = this.openCommands; - var command = new Command(msg); - openCommands.push(command); - if (this.state.isConnected()) { - this.send(msg); - } - else { - command.fail(undefined); - openCommands.splice(openCommands.indexOf(command), 1); - } - return command.promise; - }; - Commands.prototype.fail = function () { - var openCommands = this.openCommands; - var command; - for (var i = 0; i < openCommands.length; i += 1) { - command = openCommands.pop(); - command.fail(); - } - }; - Commands.prototype.extract = function (clientMsgId) { - var openCommands = this.openCommands; - var openCommandsLength = openCommands.length; - var command; - var index = 0; - while (index < openCommandsLength) { - var command = openCommands[index]; - if (command.msg.clientMsgId === clientMsgId) { - openCommands.splice(index, 1); - return command; - } - index += 1; - } - }; - return Commands; -}()); -exports.Commands = Commands; +var guaranteed_commands_1 = require('./guaranteed_commands'); +var commands_1 = require('./commands'); var Connect = (function (_super) { __extends(Connect, _super); function Connect(params) { _super.call(this); - this.adapter = params.adapter; this.encodeDecode = params.encodeDecode; this.protocol = params.protocol; this.initialization(); } + Connect.prototype.getAdapter = function () { + return this.adapter; + }; Connect.prototype.setAdapter = function (adapter) { this.adapter = adapter; }; Connect.prototype.initialization = function () { this.state = new state_1.State(); - this.guaranteedCommands = new GuaranteedCommands({ + this.guaranteedCommands = new guaranteed_commands_1.GuaranteedCommands({ state: this.state, send: this.send.bind(this) }); - this.commands = new Commands({ + this.commands = new commands_1.Commands({ state: this.state, send: this.send.bind(this) }); @@ -164,7 +48,7 @@ var Connect = (function (_super) { _this._onEnd(e); }; adapter.connect(); - return def; + return def.promise(); }; Connect.prototype.onData = function (data) { this.encodeDecode.decode(data); diff --git a/lib/connect.js.map b/lib/connect.js.map index 1c8ee38..8ddeacb 100644 --- a/lib/connect.js.map +++ b/lib/connect.js.map @@ -1 +1 @@ -{"version":3,"file":"connect.js","sourceRoot":"","sources":["connect.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAEb,uBAA2B,QAAQ,CAAC,CAAA;AAEpC,sBAAoB,SAAS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diff --git a/lib/connect.ts b/lib/connect.ts index d707fa4..fc8cf09 100644 --- a/lib/connect.ts +++ b/lib/connect.ts @@ -9,7 +9,6 @@ import {Commands} from './commands'; import {Command} from './command'; export interface IConnectionParams { - adapter: any encodeDecode: any protocol: any } @@ -24,15 +23,18 @@ export class Connect extends EventEmitter { private commands: Commands; constructor(params: IConnectionParams) { - super() + super(); - this.adapter = params.adapter; this.encodeDecode = params.encodeDecode; this.protocol = params.protocol; this.initialization(); } + public getAdapter() { + return this.adapter; + } + public setAdapter(adapter: any) { this.adapter = adapter; } @@ -53,8 +55,8 @@ export class Connect extends EventEmitter { ); } - public start() { - var def = $.Deferred(); + public start(): JQueryPromise { + var def = $.Deferred(); var adapter = this.adapter; adapter.onOpen = () => { @@ -69,7 +71,7 @@ export class Connect extends EventEmitter { adapter.connect(); - return def; + return def.promise(); } private onData(data) { diff --git a/lib/guaranteed_command.d.ts b/lib/guaranteed_command.d.ts index c24adbf..f7779bc 100644 --- a/lib/guaranteed_command.d.ts +++ b/lib/guaranteed_command.d.ts @@ -3,5 +3,6 @@ export declare class GuaranteedCommand { promise: JQueryDeferred; constructor(msg: any); done(msg: any): void; + fail(msg: any): void; private destroy(); } diff --git a/lib/guaranteed_command.js b/lib/guaranteed_command.js index 2e60284..14dd004 100644 --- a/lib/guaranteed_command.js +++ b/lib/guaranteed_command.js @@ -8,6 +8,10 @@ var GuaranteedCommand = (function () { this.promise.resolve(msg); this.destroy(); }; + GuaranteedCommand.prototype.fail = function (msg) { + this.promise.reject(msg); + this.destroy(); + }; GuaranteedCommand.prototype.destroy = function () { delete this.msg; }; diff --git a/lib/guaranteed_command.js.map b/lib/guaranteed_command.js.map index 8c7635d..8697221 100644 --- a/lib/guaranteed_command.js.map +++ b/lib/guaranteed_command.js.map @@ -1 +1 @@ -{"version":3,"file":"guaranteed_command.js","sourceRoot":"","sources":["guaranteed_command.ts"],"names":[],"mappings":";AAAA;IAKI,2BAAY,GAAQ;QAChB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAEM,gCAAI,GAAX,UAAY,GAAQ;QAChB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEO,mCAAO,GAAf;QACI,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IACL,wBAAC;AAAD,CAAC,AAlBD,IAkBC;AAlBY,yBAAiB,oBAkB7B,CAAA"} \ No newline at end of file +{"version":3,"file":"guaranteed_command.js","sourceRoot":"","sources":["guaranteed_command.ts"],"names":[],"mappings":";AAAA;IAKI,2BAAY,GAAQ;QAChB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAEM,gCAAI,GAAX,UAAY,GAAQ;QAChB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEM,gCAAI,GAAX,UAAY,GAAQ;QAChB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEO,mCAAO,GAAf;QACI,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IACL,wBAAC;AAAD,CAAC,AAvBD,IAuBC;AAvBY,yBAAiB,oBAuB7B,CAAA"} \ No newline at end of file diff --git a/lib/guaranteed_commands.d.ts b/lib/guaranteed_commands.d.ts index 442912a..eab6448 100644 --- a/lib/guaranteed_commands.d.ts +++ b/lib/guaranteed_commands.d.ts @@ -5,7 +5,5 @@ export declare class GuaranteedCommands { constructor(params: any); create(msg: any): JQueryDeferred; resend(): void; - findAndResolve(msg: any, clientMsgId: any): boolean; - private find(clientMsgId); - private delete(command); + extract(clientMsgId: string): any; } diff --git a/lib/guaranteed_commands.js b/lib/guaranteed_commands.js index 85d143b..bfc8012 100644 --- a/lib/guaranteed_commands.js +++ b/lib/guaranteed_commands.js @@ -21,23 +21,20 @@ var GuaranteedCommands = (function () { }) .forEach(this.send); }; - GuaranteedCommands.prototype.findAndResolve = function (msg, clientMsgId) { - var command = this.find(clientMsgId); - if (command) { - this.delete(command); - command.done(msg); - return true; + GuaranteedCommands.prototype.extract = function (clientMsgId) { + var openCommands = this.openCommands; + var openCommandsLength = openCommands.length; + var command; + var index = 0; + while (index < openCommandsLength) { + var command = openCommands[index]; + if (command.msg.clientMsgId === clientMsgId) { + openCommands.splice(index, 1); + return command; + } + index += 1; } }; - GuaranteedCommands.prototype.find = function (clientMsgId) { - return this.openCommands.find(function (command) { - return command.msg.clientMsgId === clientMsgId; - }); - }; - GuaranteedCommands.prototype.delete = function (command) { - var index = this.openCommands.indexOf(command); - this.openCommands.splice(index, 1); - }; return GuaranteedCommands; }()); exports.GuaranteedCommands = GuaranteedCommands; diff --git a/lib/guaranteed_commands.js.map b/lib/guaranteed_commands.js.map index cf63897..ab6e690 100644 --- a/lib/guaranteed_commands.js.map +++ b/lib/guaranteed_commands.js.map @@ -1 +1 @@ -{"version":3,"file":"guaranteed_commands.js","sourceRoot":"","sources":["guaranteed_commands.ts"],"names":[],"mappings":";AAAA,mCAAgC,sBAAsB,CAAC,CAAA;AAGvD;IAMI,4BAAY,MAAW;QACnB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IAC3B,CAAC;IAEM,mCAAM,GAAb,UAAc,GAAQ;QAClB,IAAI,OAAO,GAAG,IAAI,sCAAiB,CAAC,GAAG,CAAC,CAAC;QAEzC,IAAI,CAAC,YAAY,CAAC,IAAI,CA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C,CAAC;gBAC9B,MAAM,CAAC,OAAO,CAAC;YACnB,CAAC;YACD,KAAK,IAAI,CAAC,CAAC;QACf,CAAC;IACL,CAAC;IAEL,yBAAC;AAAD,CAAC,AA9CD,IA8CC;AA9CY,0BAAkB,qBA8C9B,CAAA"} \ No newline at end of file From d24329b5018cdd3411bc43c98c67ef7d860dcb33 Mon Sep 17 00:00:00 2001 From: vspirin Date: Fri, 10 Jun 2016 17:11:36 +0300 Subject: [PATCH 2/4] bump version 1.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 193fe5c..02b6eff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "connect-ts-api", - "version": "1.0.2", + "version": "1.1.2", "main": "lib/connect.js", "typescript": { "main": "lib/connect.ts" From 7373417fd863dd6683b76a526368a95835aa7e85 Mon Sep 17 00:00:00 2001 From: vspirin Date: Fri, 10 Jun 2016 17:55:05 +0300 Subject: [PATCH 3/4] move clientMsgId from protocol into connection --- lib/command.d.ts | 4 +- lib/command.js | 6 +-- lib/command.js.map | 2 +- lib/command.ts | 9 ++--- lib/commands.d.ts | 5 ++- lib/commands.js | 18 +++++---- lib/commands.js.map | 2 +- lib/commands.ts | 23 +++++++----- lib/connect.d.ts | 10 +++-- lib/connect.js | 55 +++++++++++++++++++--------- lib/connect.js.map | 2 +- lib/connect.ts | 67 ++++++++++++++++++++++------------ lib/guaranteed_command.d.ts | 5 ++- lib/guaranteed_command.js | 6 ++- lib/guaranteed_command.js.map | 2 +- lib/guaranteed_command.ts | 10 +++-- lib/guaranteed_commands.d.ts | 5 ++- lib/guaranteed_commands.js | 16 ++++---- lib/guaranteed_commands.js.map | 2 +- lib/guaranteed_commands.ts | 20 +++++----- package.json | 3 +- 21 files changed, 161 insertions(+), 111 deletions(-) diff --git a/lib/command.d.ts b/lib/command.d.ts index e5675fb..5339225 100644 --- a/lib/command.d.ts +++ b/lib/command.d.ts @@ -1,7 +1,7 @@ export declare class Command { - private msg; + clientMsgId: string; promise: JQueryDeferred; - constructor(msg: any); + constructor(params: any); done(respond: any): void; fail(respond: any): void; private destroy(); diff --git a/lib/command.js b/lib/command.js index 7c56f4a..1993d08 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1,7 +1,7 @@ "use strict"; var Command = (function () { - function Command(msg) { - this.msg = msg; + function Command(params) { + this.clientMsgId = params.clientMsgId; this.promise = $.Deferred(); } Command.prototype.done = function (respond) { @@ -13,7 +13,7 @@ var Command = (function () { this.destroy(); }; Command.prototype.destroy = function () { - delete this.msg; + delete this.clientMsgId; }; return Command; }()); diff --git a/lib/command.js.map b/lib/command.js.map index 452e87e..8032c78 100644 --- a/lib/command.js.map +++ b/lib/command.js.map @@ -1 +1 @@ -{"version":3,"file":"command.js","sourceRoot":"","sources":["command.ts"],"names":[],"mappings":";AAAA;IAKI,iBAAY,GAAQ;QAChB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAEM,sBAAI,GAAX,UAAY,OAAY;QACpB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEM,sBAAI,GAAX,UAAY,OAAY;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEO,yBAAO,GAAf;QACI,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IACL,cAAC;AAAD,CAAC,AAvBD,IAuBC;AAvBY,eAAO,UAuBnB,CAAA"} \ No newline at end of file +{"version":3,"file":"command.js","sourceRoot":"","sources":["command.ts"],"names":[],"mappings":";AAAA;IAII,iBAAY,MAAM;QACd,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAEM,sBAAI,GAAX,UAAY,OAAY;QACpB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEM,sBAAI,GAAX,UAAY,OAAY;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEO,yBAAO,GAAf;QACI,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IACL,cAAC;AAAD,CAAC,AAtBD,IAsBC;AAtBY,eAAO,UAsBnB,CAAA"} \ No newline at end of file diff --git a/lib/command.ts b/lib/command.ts index 4816f24..be2d119 100644 --- a/lib/command.ts +++ b/lib/command.ts @@ -1,10 +1,9 @@ export class Command { - - private msg: any; + public clientMsgId: string; public promise: JQueryDeferred; - constructor(msg: any) { - this.msg = msg; + constructor(params) { + this.clientMsgId = params.clientMsgId; this.promise = $.Deferred(); } @@ -19,6 +18,6 @@ export class Command { } private destroy() { - delete this.msg; + delete this.clientMsgId; } } diff --git a/lib/commands.d.ts b/lib/commands.d.ts index 1f1e3d6..916bdcc 100644 --- a/lib/commands.d.ts +++ b/lib/commands.d.ts @@ -1,9 +1,10 @@ +import { Command } from './command'; export declare class Commands { private state; private send; private openCommands; constructor(params: any); - create(msg: any): JQueryDeferred; + create(params: any): JQueryDeferred; fail(): void; - extract(clientMsgId: string): any; + extract(clientMsgId: string): Command; } diff --git a/lib/commands.js b/lib/commands.js index 4d04112..eb3cd14 100644 --- a/lib/commands.js +++ b/lib/commands.js @@ -6,9 +6,13 @@ var Commands = (function () { this.send = params.send; this.openCommands = []; } - Commands.prototype.create = function (msg) { + Commands.prototype.create = function (params) { + var clientMsgId = params.clientMsgId; + var msg = params.msg; var openCommands = this.openCommands; - var command = new command_1.Command(msg); + var command = new command_1.Command({ + clientMsgId: clientMsgId + }); openCommands.push(command); if (this.state.isConnected()) { this.send(msg); @@ -31,14 +35,12 @@ var Commands = (function () { var openCommands = this.openCommands; var openCommandsLength = openCommands.length; var command; - var index = 0; - while (index < openCommandsLength) { - var command = openCommands[index]; - if (command.msg.clientMsgId === clientMsgId) { - openCommands.splice(index, 1); + for (var i = 0; i < openCommandsLength; i += 1) { + command = openCommands[i]; + if (command.clientMsgId === clientMsgId) { + openCommands.splice(i, 1); return command; } - index += 1; } }; return Commands; diff --git a/lib/commands.js.map b/lib/commands.js.map index aa4bf88..2fe4f8f 100644 --- a/lib/commands.js.map +++ b/lib/commands.js.map @@ -1 +1 @@ -{"version":3,"file":"commands.js","sourceRoot":"","sources":["commands.ts"],"names":[],"mappings":";AAAA,wBAAsB,WAAW,CAAC,CAAA;AAGlC;IAMI,kBAAY,MAAW;QACnB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IAC3B,CAAC;IAEM,yBAAM,GAAb,UAAc,GAAQ;QAClB,IAAI,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QAErC,IAAI,OAAO,GAAG,IAAI,iBAAO,CAAC,GAAG,CAAC,CAAC;QAE/B,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE3B,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;YAC3B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,OAAO,CAAC,IAAI,CAAM,SAAS,CAAC,CAAC;YAC7B,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;QAC1D,CAAC;QACD,MA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C,EAAE,CAAC,GAAG,kBAAkB,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7C,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;YAC1B,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC;gBACtC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC1B,MAAM,CAAC,OAAO,CAAC;YACnB,CAAC;QACL,CAAC;IACL,CAAC;IAEL,eAAC;AAAD,CAAC,AAvDD,IAuDC;AAvDY,gBAAQ,WAuDpB,CAAA"} \ No newline at end of file diff --git a/lib/commands.ts b/lib/commands.ts index fa6c331..6a6c6ef 100644 --- a/lib/commands.ts +++ b/lib/commands.ts @@ -5,7 +5,7 @@ export class Commands { private state: State; private send: any; - private openCommands: any; + private openCommands: Command[]; constructor(params: any) { this.state = params.state; @@ -13,10 +13,15 @@ export class Commands { this.openCommands = []; } - public create(msg: any): JQueryDeferred { + public create(params): JQueryDeferred { + var clientMsgId = params.clientMsgId; + var msg = params.msg; + var openCommands = this.openCommands; - var command = new Command(msg); + var command = new Command({ + clientMsgId: clientMsgId + }); openCommands.push(command); @@ -38,18 +43,16 @@ export class Commands { } } - public extract(clientMsgId: string): any { + public extract(clientMsgId: string): Command { var openCommands = this.openCommands; var openCommandsLength = openCommands.length; var command; - var index = 0; - while (index < openCommandsLength) { - var command = openCommands[index]; - if (command.msg.clientMsgId === clientMsgId) { - openCommands.splice(index, 1); + for (var i = 0; i < openCommandsLength; i += 1) { + command = openCommands[i]; + if (command.clientMsgId === clientMsgId) { + openCommands.splice(i, 1); return command; } - index += 1; } } diff --git a/lib/connect.d.ts b/lib/connect.d.ts index 21710a6..f6fa656 100644 --- a/lib/connect.d.ts +++ b/lib/connect.d.ts @@ -17,12 +17,14 @@ export declare class Connect extends EventEmitter { start(): JQueryPromise; private onData(data); private onOpen(); - sendGuaranteedCommand(payloadType: any, params: any): JQueryDeferred; - sendCommand(payloadType: any, params: any): JQueryDeferred; - private send(msg); + sendGuaranteedCommand(payloadType: number, params: any): JQueryDeferred; + sendCommand(payloadType: number, params: any): JQueryDeferred; + private send(data); private onMessage(data); + private processData(clientMsgId, payloadType, msg); + private extractCommand(clientMsgId); protected isError(payloadType: any): boolean; - protected processMessage(msg: any, clientMsgId: string, payloadType: number): void; + protected processMessage(command: any, msg: any, payloadType: any): void; protected processPushEvent(msg: any, payloadType: any): void; private _onEnd(e); isDisconnected(): boolean; diff --git a/lib/connect.js b/lib/connect.js index e9358d4..baa6d42 100644 --- a/lib/connect.js +++ b/lib/connect.js @@ -4,6 +4,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; +var hat = require('hat'); var events_1 = require('events'); var state_1 = require('./state'); var guaranteed_commands_1 = require('./guaranteed_commands'); @@ -59,14 +60,23 @@ var Connect = (function (_super) { this.onConnect(); }; Connect.prototype.sendGuaranteedCommand = function (payloadType, params) { - return this.guaranteedCommands.create(this.protocol.encode(payloadType, params)); + var clientMsgId = hat(); + var msg = this.protocol.encode(payloadType, params, clientMsgId); + return this.guaranteedCommands.create({ + clientMsgId: clientMsgId, + msg: msg + }); }; Connect.prototype.sendCommand = function (payloadType, params) { - return this.commands.create(this.protocol.encode(payloadType, params)); + var clientMsgId = hat(); + var msg = this.protocol.encode(payloadType, params, clientMsgId); + return this.commands.create({ + clientMsgId: clientMsgId, + msg: msg + }); }; - Connect.prototype.send = function (msg) { - var data = this.encodeDecode.encode(msg); - this.adapter.send(data); + Connect.prototype.send = function (data) { + this.adapter.send(this.encodeDecode.encode(data)); }; Connect.prototype.onMessage = function (data) { data = this.protocol.decode(data); @@ -74,23 +84,34 @@ var Connect = (function (_super) { var payloadType = data.payloadType; var clientMsgId = data.clientMsgId; if (clientMsgId) { - var command = this.guaranteedCommands.extract(clientMsgId) || this.commands.extract(clientMsgId); - if (command) { - if (this.isError(payloadType)) { - command.fail(msg); - } - else { - command.done(msg); - } - return; - } + this.processData(clientMsgId, payloadType, msg); + } + else { + this.processPushEvent(msg, payloadType); } - this.processPushEvent(msg, payloadType); + }; + Connect.prototype.processData = function (clientMsgId, payloadType, msg) { + var command = this.extractCommand(clientMsgId); + if (command) { + this.processMessage(command, msg, payloadType); + } + else { + this.processPushEvent(msg, payloadType); + } + }; + Connect.prototype.extractCommand = function (clientMsgId) { + return this.guaranteedCommands.extract(clientMsgId) || this.commands.extract(clientMsgId); }; Connect.prototype.isError = function (payloadType) { return false; }; - Connect.prototype.processMessage = function (msg, clientMsgId, payloadType) { + Connect.prototype.processMessage = function (command, msg, payloadType) { + if (this.isError(payloadType)) { + command.fail(msg); + } + else { + command.done(msg); + } }; Connect.prototype.processPushEvent = function (msg, payloadType) { this.emit(payloadType, msg); diff --git a/lib/connect.js.map b/lib/connect.js.map index 8ddeacb..fcbe06c 100644 --- a/lib/connect.js.map +++ b/lib/connect.js.map @@ -1 +1 @@ -{"version":3,"file":"connect.js","sourceRoot":"","sources":["connect.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAEb,uBAA2B,QAAQ,CAAC,CAAA;AAEpC,sBAAoB,SAAS,CAAC,CAAA;AAC9B,oCAAiC,uBAAuB,CAAC,CAAA;AAEzD,yBAAuB,YAAY,CAAC,CAAA;AAQpC;IAA6B,2BAAY;IASrC,iBAAY,MAAyB;QACjC,iBAAO,CAAA;QAEP,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAEhC,IAAI,CAAC,cAAc,EAAE,CAAC;IAC1B,CAAC;IAEM,4BAAU,GAAjB;QACI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAEM,4BAAU,GAAjB,UAAkB,OAAY;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAEO,gCAA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ect.ts @@ -1,7 +1,7 @@ 'use strict'; +var hat = require('hat'); import {EventEmitter} from 'events'; - import {State} from './state'; import {GuaranteedCommands} from './guaranteed_commands'; import {GuaranteedCommand} from './guaranteed_command'; @@ -85,21 +85,30 @@ export class Connect extends EventEmitter { this.onConnect(); } - public sendGuaranteedCommand(payloadType, params): JQueryDeferred { - return this.guaranteedCommands.create( - this.protocol.encode(payloadType, params) - ); + public sendGuaranteedCommand(payloadType: number, params): JQueryDeferred { + var clientMsgId: string = hat(); + var msg = this.protocol.encode(payloadType, params, clientMsgId); + + return this.guaranteedCommands.create({ + clientMsgId: clientMsgId, + msg: msg + }); } - public sendCommand(payloadType, params): JQueryDeferred { - return this.commands.create( - this.protocol.encode(payloadType, params) - ); + public sendCommand(payloadType: number, params): JQueryDeferred { + var clientMsgId: string = hat(); + var msg = this.protocol.encode(payloadType, params, clientMsgId); + + return this.commands.create({ + clientMsgId: clientMsgId, + msg: msg + }); } - private send(msg) { - var data = this.encodeDecode.encode(msg); - this.adapter.send(data); + private send(data) { + this.adapter.send( + this.encodeDecode.encode(data) + ); } private onMessage(data) { @@ -109,17 +118,23 @@ export class Connect extends EventEmitter { var clientMsgId = data.clientMsgId; if (clientMsgId) { - var command = this.guaranteedCommands.extract(clientMsgId) || this.commands.extract(clientMsgId); - if (command) { - if (this.isError(payloadType)) { - command.fail(msg); - } else { - command.done(msg); - } - return; - } + this.processData(clientMsgId, payloadType, msg); + } else { + this.processPushEvent(msg, payloadType); } - this.processPushEvent(msg, payloadType); + } + + private processData(clientMsgId, payloadType, msg) { + var command = this.extractCommand(clientMsgId); + if (command) { + this.processMessage(command, msg, payloadType); + } else { + this.processPushEvent(msg, payloadType); + } + } + + private extractCommand(clientMsgId) { + return this.guaranteedCommands.extract(clientMsgId) || this.commands.extract(clientMsgId); } protected isError(payloadType): boolean { @@ -127,8 +142,12 @@ export class Connect extends EventEmitter { return false; } - protected processMessage(msg: any, clientMsgId: string, payloadType: number) { - + protected processMessage(command, msg, payloadType) { + if (this.isError(payloadType)) { + command.fail(msg); + } else { + command.done(msg); + } } protected processPushEvent(msg, payloadType) { diff --git a/lib/guaranteed_command.d.ts b/lib/guaranteed_command.d.ts index f7779bc..b9be387 100644 --- a/lib/guaranteed_command.d.ts +++ b/lib/guaranteed_command.d.ts @@ -1,7 +1,8 @@ export declare class GuaranteedCommand { - private msg; + clientMsgId: string; + msg: any; promise: JQueryDeferred; - constructor(msg: any); + constructor(params: any); done(msg: any): void; fail(msg: any): void; private destroy(); diff --git a/lib/guaranteed_command.js b/lib/guaranteed_command.js index 14dd004..ec1c050 100644 --- a/lib/guaranteed_command.js +++ b/lib/guaranteed_command.js @@ -1,7 +1,8 @@ "use strict"; var GuaranteedCommand = (function () { - function GuaranteedCommand(msg) { - this.msg = msg; + function GuaranteedCommand(params) { + this.clientMsgId = params.clientMsgId; + this.msg = params.msg; this.promise = $.Deferred(); } GuaranteedCommand.prototype.done = function (msg) { @@ -13,6 +14,7 @@ var GuaranteedCommand = (function () { this.destroy(); }; GuaranteedCommand.prototype.destroy = function () { + delete this.clientMsgId; delete this.msg; }; return GuaranteedCommand; diff --git a/lib/guaranteed_command.js.map b/lib/guaranteed_command.js.map index 8697221..9512a08 100644 --- a/lib/guaranteed_command.js.map +++ b/lib/guaranteed_command.js.map @@ -1 +1 @@ -{"version":3,"file":"guaranteed_command.js","sourceRoot":"","sources":["guaranteed_command.ts"],"names":[],"mappings":";AAAA;IAKI,2BAAY,GAAQ;QAChB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAEM,gCAAI,GAAX,UAAY,GAAQ;QAChB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEM,gCAAI,GAAX,UAAY,GAAQ;QAChB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEO,mCAAO,GAAf;QACI,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IACL,wBAAC;AAAD,CAAC,AAvBD,IAuBC;AAvBY,yBAAiB,oBAuB7B,CAAA"} \ No newline at end of file +{"version":3,"file":"guaranteed_command.js","sourceRoot":"","sources":["guaranteed_command.ts"],"names":[],"mappings":";AAAA;IAKI,2BAAY,MAAM;QACd,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAEM,gCAAI,GAAX,UAAY,GAAQ;QAChB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEM,gCAAI,GAAX,UAAY,GAAQ;QAChB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEO,mCAAO,GAAf;QACI,OAAO,IAAI,CAAC,WAAW,CAAC;QACxB,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IACL,wBAAC;AAAD,CAAC,AAzBD,IAyBC;AAzBY,yBAAiB,oBAyB7B,CAAA"} \ No newline at end of file diff --git a/lib/guaranteed_command.ts b/lib/guaranteed_command.ts index c9548c1..2c94731 100644 --- a/lib/guaranteed_command.ts +++ b/lib/guaranteed_command.ts @@ -1,10 +1,11 @@ export class GuaranteedCommand { - - private msg: any; + public clientMsgId: string; + public msg: any; public promise: JQueryDeferred; - constructor(msg: any) { - this.msg = msg; + constructor(params) { + this.clientMsgId = params.clientMsgId; + this.msg = params.msg; this.promise = $.Deferred(); } @@ -19,6 +20,7 @@ export class GuaranteedCommand { } private destroy() { + delete this.clientMsgId; delete this.msg; } } diff --git a/lib/guaranteed_commands.d.ts b/lib/guaranteed_commands.d.ts index eab6448..1e155ab 100644 --- a/lib/guaranteed_commands.d.ts +++ b/lib/guaranteed_commands.d.ts @@ -1,9 +1,10 @@ +import { GuaranteedCommand } from './guaranteed_command'; export declare class GuaranteedCommands { private state; private send; private openCommands; constructor(params: any); - create(msg: any): JQueryDeferred; + create(params: any): JQueryDeferred; resend(): void; - extract(clientMsgId: string): any; + extract(clientMsgId: string): GuaranteedCommand; } diff --git a/lib/guaranteed_commands.js b/lib/guaranteed_commands.js index bfc8012..76d7a50 100644 --- a/lib/guaranteed_commands.js +++ b/lib/guaranteed_commands.js @@ -6,11 +6,11 @@ var GuaranteedCommands = (function () { this.send = params.send; this.openCommands = []; } - GuaranteedCommands.prototype.create = function (msg) { - var command = new guaranteed_command_1.GuaranteedCommand(msg); + GuaranteedCommands.prototype.create = function (params) { + var command = new guaranteed_command_1.GuaranteedCommand(params); this.openCommands.push(command); if (this.state.isConnected()) { - this.send(msg); + this.send(command.msg); } return command.promise; }; @@ -25,14 +25,12 @@ var GuaranteedCommands = (function () { var openCommands = this.openCommands; var openCommandsLength = openCommands.length; var command; - var index = 0; - while (index < openCommandsLength) { - var command = openCommands[index]; - if (command.msg.clientMsgId === clientMsgId) { - openCommands.splice(index, 1); + for (var i = 0; i < openCommandsLength; i += 1) { + command = openCommands[i]; + if (command.clientMsgId === clientMsgId) { + openCommands.splice(i, 1); return command; } - index += 1; } }; return GuaranteedCommands; diff --git a/lib/guaranteed_commands.js.map b/lib/guaranteed_commands.js.map index ab6e690..853c761 100644 --- a/lib/guaranteed_commands.js.map +++ b/lib/guaranteed_commands.js.map @@ -1 +1 @@ -{"version":3,"file":"guaranteed_commands.js","sourceRoot":"","sources":["guaranteed_commands.ts"],"names":[],"mappings":";AAAA,mCAAgC,sBAAsB,CAAC,CAAA;AAGvD;IAMI,4BAAY,M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GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;YAC1B,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC;gBACtC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC1B,MAAM,CAAC,OAAO,CAAC;YACnB,CAAC;QACL,CAAC;IACL,CAAC;IAEL,yBAAC;AAAD,CAAC,AA5CD,IA4CC;AA5CY,0BAAkB,qBA4C9B,CAAA"} \ No newline at end of file diff --git a/lib/guaranteed_commands.ts b/lib/guaranteed_commands.ts index 1285bc7..c718cde 100644 --- a/lib/guaranteed_commands.ts +++ b/lib/guaranteed_commands.ts @@ -5,7 +5,7 @@ export class GuaranteedCommands { private state: State; private send: any; - private openCommands: any; + private openCommands: GuaranteedCommand[]; constructor(params: any) { this.state = params.state; @@ -13,13 +13,13 @@ export class GuaranteedCommands { this.openCommands = []; } - public create(msg: any): JQueryDeferred { - var command = new GuaranteedCommand(msg); + public create(params): JQueryDeferred { + var command = new GuaranteedCommand(params); this.openCommands.push(command); if (this.state.isConnected()) { - this.send(msg); + this.send(command.msg); } return command.promise; } @@ -32,18 +32,16 @@ export class GuaranteedCommands { .forEach(this.send); } - public extract(clientMsgId: string): any { + public extract(clientMsgId: string): GuaranteedCommand { var openCommands = this.openCommands; var openCommandsLength = openCommands.length; var command; - var index = 0; - while (index < openCommandsLength) { - var command = openCommands[index]; - if (command.msg.clientMsgId === clientMsgId) { - openCommands.splice(index, 1); + for (var i = 0; i < openCommandsLength; i += 1) { + command = openCommands[i]; + if (command.clientMsgId === clientMsgId) { + openCommands.splice(i, 1); return command; } - index += 1; } } diff --git a/package.json b/package.json index 02b6eff..e32b6d9 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "author": "Spotware Services ", "private": true, "dependencies": { - "ts-loader": "0.8.2" + "hat": "0.0.3", + "ts-loader": "0.8.2" }, "devDependencies": { "typescript": "1.8.10" From a509e6946a5bb532e97020f0093eea7f3be80c1a Mon Sep 17 00:00:00 2001 From: vspirin Date: Mon, 13 Jun 2016 09:52:30 +0300 Subject: [PATCH 4/4] bump v1.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e32b6d9..a2d9ec8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "connect-ts-api", - "version": "1.1.2", + "version": "1.2.0", "main": "lib/connect.js", "typescript": { "main": "lib/connect.ts"