From e6ed0c28a37f10489841733994ca65b9672a887b Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Thu, 9 Apr 2015 16:37:55 +0200 Subject: [PATCH] wip : replace Job by promises --- src/js/utils/Job.js | 29 ---------------- src/piskel-script-list.js | 1 - test/js/utils/JobTest.js | 73 --------------------------------------- 3 files changed, 103 deletions(-) delete mode 100644 src/js/utils/Job.js delete mode 100644 test/js/utils/JobTest.js diff --git a/src/js/utils/Job.js b/src/js/utils/Job.js deleted file mode 100644 index de9043e1..00000000 --- a/src/js/utils/Job.js +++ /dev/null @@ -1,29 +0,0 @@ -(function () { - var ns = $.namespace('pskl.utils'); - - ns.Job = function (cfg) { - this.args = cfg.args; - this.items = cfg.items; - - this.process = cfg.process; - this.onProcessEnd = cfg.onProcessEnd; - this.onComplete = cfg.onComplete; - - this.completed_ = 0; - }; - - ns.Job.prototype.start = function () { - this.items.forEach(function (item, index) { - this.process(item, this.processCallback.bind(this, index)); - }.bind(this)) - }; - - ns.Job.prototype.processCallback = function (index, args) { - this.completed_++; - this.onProcessEnd(args, index); - - if (this.completed_ === this.items.length) { - this.onComplete(this.args); - } - } -})(); \ No newline at end of file diff --git a/src/piskel-script-list.js b/src/piskel-script-list.js index a70348a3..39cf6e78 100644 --- a/src/piskel-script-list.js +++ b/src/piskel-script-list.js @@ -24,7 +24,6 @@ "js/utils/FileUtilsDesktop.js", "js/utils/FrameTransform.js", "js/utils/FrameUtils.js", - "js/utils/Job.js", "js/utils/LayerUtils.js", "js/utils/ImageResizer.js", "js/utils/PixelUtils.js", diff --git a/test/js/utils/JobTest.js b/test/js/utils/JobTest.js deleted file mode 100644 index 41f57eac..00000000 --- a/test/js/utils/JobTest.js +++ /dev/null @@ -1,73 +0,0 @@ -describe("Job for // async", function() { - - beforeEach(function() {}); - afterEach(function() {}); - - it("completes synchronous job", function() { - // when - var isComplete = false; - var result = null; - // then - var job = new pskl.utils.Job({ - items : [0,1,2,3,4], - args : { - store : [] - }, - process : function (item, callback) { - callback(item+5) - }, - onProcessEnd : function (value, index) { - this.args.store[index] = value; - }, - onComplete : function (args) { - isComplete = true; - result = args.store; - } - }); - - job.start(); - - // verify - expect(isComplete).toBe(true); - expect(result).toEqual([5,6,7,8,9]); - }); - - describe("async", function () { - // when - var isComplete = false; - var result = null; - - beforeEach(function(done) { - // then - var job = new pskl.utils.Job({ - items : [0,1,2,3,4], - args : { - store : [] - }, - process : function (item, callback) { - setTimeout(function (item, callback) { - callback(item+5); - }.bind(this, item, callback), 100 - (item * 20)); - }, - onProcessEnd : function (value, index) { - console.log('Processed ', index); - this.args.store[index] = value; - }, - onComplete : function (args) { - isComplete = true; - result = args.store; - done(); - } - }); - - job.start(); - }); - it("completes asynchronous job", function() { - // verify - expect(isComplete).toBe(true); - expect(result).toEqual([5,6,7,8,9]); - }); - - }) - -}); \ No newline at end of file