Mercurial > pub > ImplabJs
comparison src/djol/_OneshotTool.js @ 34:27e8e9e38e07 default tip
Слияние
| author | nickolay |
|---|---|
| date | Wed, 05 Jun 2019 20:44:15 +0300 |
| parents | 8af8e840dd49 1dc2fd263b90 |
| children |
comparison
equal
deleted
inserted
replaced
| 33:8af8e840dd49 | 34:27e8e9e38e07 |
|---|---|
| 1 define(["dojo/_base/declare", "implab/safe", "implab/guard", "ol3/_ToolBase", "ol3/ToolType"], | |
| 2 | |
| 3 function (declare, safe, guard, _ToolBase, ToolType) { | |
| 4 return declare([_ToolBase], { | |
| 5 _pending: null, | |
| 6 | |
| 7 _lastResult: null, | |
| 8 | |
| 9 toolType: ToolType.Oneshot, | |
| 10 | |
| 11 invoke: function () { | |
| 12 }, | |
| 13 | |
| 14 onActivating: function () { | |
| 15 var me = this; | |
| 16 | |
| 17 // start the operation | |
| 18 me._lastResult = me._pending = guard(me, "invoke"); | |
| 19 | |
| 20 return this.inherited(arguments); | |
| 21 }, | |
| 22 | |
| 23 onActivated: function () { | |
| 24 var me = this; | |
| 25 | |
| 26 // fire the activate event | |
| 27 this.inherited(arguments); | |
| 28 | |
| 29 me._pending.then(function () { | |
| 30 if (me._pending) { | |
| 31 me.log("Operation finished, deactivating."); | |
| 32 me._pending = null; | |
| 33 me.deactivate(); | |
| 34 } | |
| 35 }, function (ex) { | |
| 36 if (me._pending) { | |
| 37 me.error("Operation failed, deactivating: {0}", ex); | |
| 38 me._pending = null; | |
| 39 me.deactivate(); | |
| 40 } | |
| 41 }); | |
| 42 }, | |
| 43 | |
| 44 onDeactivated: function () { | |
| 45 var d = this._pending; | |
| 46 if (d) { | |
| 47 this.log("Cancelling pending operation"); | |
| 48 this._pending = null; | |
| 49 d.cancel(); | |
| 50 } | |
| 51 | |
| 52 return this.inherited(arguments); | |
| 53 }, | |
| 54 | |
| 55 run: function () { | |
| 56 var me = this; | |
| 57 | |
| 58 return me.activate().then(function () { | |
| 59 return me._lastResult; | |
| 60 }); | |
| 61 } | |
| 62 }); | |
| 63 }); |
