# HG changeset patch # User cin # Date 1496767532 -10800 # Node ID 00779cb63b127f9c6bcc9a6cbd0d7313a552ccfc # Parent 7d7059d2a810c3548e243d0ddabcc19738a0d1f5 formatting diff -r 7d7059d2a810 -r 00779cb63b12 src/implab/Uri.js --- a/src/implab/Uri.js Fri Jun 02 19:28:20 2017 +0300 +++ b/src/implab/Uri.js Tue Jun 06 19:45:32 2017 +0300 @@ -1,5 +1,5 @@ define( - [ "dojo/_base/declare" ], + [ "./declare" ], function(declare) { function parseURI(uri) { var schema, host, port, path, query, hash, i; diff -r 7d7059d2a810 -r 00779cb63b12 src/implab/Uuid.js --- a/src/implab/Uuid.js Fri Jun 02 19:28:20 2017 +0300 +++ b/src/implab/Uuid.js Tue Jun 06 19:45:32 2017 +0300 @@ -2,279 +2,277 @@ // // Copyright (c) 2010-2012 Robert Kieffer // MIT License - http://opensource.org/licenses/mit-license.php -define( - [], - function () { - 'use strict'; +define([], function () { + 'use strict'; - var _window = 'undefined' !== typeof window ? window : null; + var _window = 'undefined' !== typeof window ? window : null; - // Unique ID creation requires a high quality random # generator. We - // feature - // detect to determine the best RNG source, normalizing to a function - // that - // returns 128-bits of randomness, since that's what's usually required - var _rng, _mathRNG, _nodeRNG, _whatwgRNG, _previousRoot; + // Unique ID creation requires a high quality random # generator. We + // feature + // detect to determine the best RNG source, normalizing to a function + // that + // returns 128-bits of randomness, since that's what's usually required + var _rng, _mathRNG, _nodeRNG, _whatwgRNG, _previousRoot; - function setupBrowser() { - // Allow for MSIE11 msCrypto - var _crypto = _window.crypto || _window.msCrypto; + function setupBrowser() { + // Allow for MSIE11 msCrypto + var _crypto = _window.crypto || _window.msCrypto; - if (!_rng && _crypto && _crypto.getRandomValues) { - // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto - // - // Moderately fast, high quality - try { - var _rnds8 = new Uint8Array(16); - _whatwgRNG = _rng = function whatwgRNG() { - _crypto.getRandomValues(_rnds8); - return _rnds8; - }; - _rng(); - } catch (e) { /**/ } - } + if (!_rng && _crypto && _crypto.getRandomValues) { + // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto + // + // Moderately fast, high quality + try { + var _rnds8 = new Uint8Array(16); + _whatwgRNG = _rng = function whatwgRNG() { + _crypto.getRandomValues(_rnds8); + return _rnds8; + }; + _rng(); + } catch (e) { /**/ } + } - if (!_rng) { - // Math.random()-based (RNG) - // - // If all else fails, use Math.random(). It's fast, but is of - // unspecified - // quality. - var _rnds = new Array(16); - _mathRNG = _rng = function () { - for (var i = 0, r; i < 16; i++) { - if ((i & 0x03) === 0) { - r = Math.random() * 0x100000000; - } - _rnds[i] = r >>> ((i & 0x03) << 3) & 0xff; + if (!_rng) { + // Math.random()-based (RNG) + // + // If all else fails, use Math.random(). It's fast, but is of + // unspecified + // quality. + var _rnds = new Array(16); + _mathRNG = _rng = function () { + for (var i = 0, r; i < 16; i++) { + if ((i & 0x03) === 0) { + r = Math.random() * 0x100000000; } + _rnds[i] = r >>> ((i & 0x03) << 3) & 0xff; + } - return _rnds; - }; - if ('undefined' !== typeof console && console.warn) { - console - .warn("[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()"); - } + return _rnds; + }; + if ('undefined' !== typeof console && console.warn) { + console + .warn("[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()"); } } + } - function setupNode() { - // Node.js crypto-based RNG - - // http://nodejs.org/docs/v0.6.2/api/crypto.html - // - // Moderately fast, high quality - if ('function' === typeof require) { - try { - var _rb = require('crypto').randomBytes; - _nodeRNG = _rng = _rb && function () { - return _rb(16); - }; - _rng(); - } catch (e) { /**/ } + function setupNode() { + // Node.js crypto-based RNG - + // http://nodejs.org/docs/v0.6.2/api/crypto.html + // + // Moderately fast, high quality + if ('function' === typeof require) { + try { + var _rb = require('crypto').randomBytes; + _nodeRNG = _rng = _rb && function () { + return _rb(16); + }; + _rng(); + } catch (e) { /**/ } + } + } + + if (_window) { + setupBrowser(); + } else { + setupNode(); + } + + // Buffer class to use + var BufferClass = ('function' === typeof Buffer) ? Buffer : Array; + + // Maps for number <-> hex string conversion + var _byteToHex = []; + var _hexToByte = {}; + for (var i = 0; i < 256; i++) { + _byteToHex[i] = (i + 0x100).toString(16).substr(1); + _hexToByte[_byteToHex[i]] = i; + } + + // **`parse()` - Parse a UUID into it's component bytes** + function parse(s, buf, offset) { + var i = (buf && offset) || 0, + ii = 0; + + buf = buf || []; + s.toLowerCase().replace(/[0-9a-f]{2}/g, function (oct) { + if (ii < 16) { // Don't overflow! + buf[i + ii++] = _hexToByte[oct]; + } + }); + + // Zero out remaining bytes if string was short + while (ii < 16) { + buf[i + ii++] = 0; + } + + return buf; + } + + // **`unparse()` - Convert UUID byte array (ala parse()) into a string** + function unparse(buf, offset) { + var i = offset || 0, + bth = _byteToHex; + return bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]] + + bth[buf[i++]] + '-' + bth[buf[i++]] + bth[buf[i++]] + '-' + + bth[buf[i++]] + bth[buf[i++]] + '-' + bth[buf[i++]] + + bth[buf[i++]] + '-' + bth[buf[i++]] + bth[buf[i++]] + + bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]]; + } + + // **`v1()` - Generate time-based UUID** + // + // Inspired by https://github.com/LiosK/UUID.js + // and http://docs.python.org/library/uuid.html + + // random #'s we need to init node and clockseq + var _seedBytes = _rng(); + + // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = + // 1) + var _nodeId = [ + _seedBytes[0] | 0x01, + _seedBytes[1], + _seedBytes[2], + _seedBytes[3], + _seedBytes[4], + _seedBytes[5] + ]; + + // Per 4.2.2, randomize (14 bit) clockseq + var _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff; + + // Previous uuid creation time + var _lastMSecs = 0, + _lastNSecs = 0; + + // See https://github.com/broofa/node-uuid for API details + function v1(options, buf, offset) { + var i = buf && offset || 0; + var b = buf || []; + + options = options || {}; + + var clockseq = (options.clockseq != null) ? options.clockseq : _clockseq; + + // UUID timestamps are 100 nano-second units since the Gregorian + // epoch, + // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so + // time is handled internally as 'msecs' (integer milliseconds) and + // 'nsecs' + // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 + // 00:00. + var msecs = (options.msecs != null) ? options.msecs : new Date() + .getTime(); + + // Per 4.2.1.2, use count of uuid's generated during the current + // clock + // cycle to simulate higher resolution clock + var nsecs = (options.nsecs != null) ? options.nsecs : _lastNSecs + 1; + + // Time since last uuid creation (in msecs) + var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs) / 10000; + + // Per 4.2.1.2, Bump clockseq on clock regression + if (dt < 0 && options.clockseq == null) { + clockseq = clockseq + 1 & 0x3fff; + } + + // Reset nsecs if clock regresses (new clockseq) or we've moved onto + // a new + // time interval + if ((dt < 0 || msecs > _lastMSecs) && options.nsecs == null) { + nsecs = 0; + } + + // Per 4.2.1.2 Throw error if too many uuids are requested + if (nsecs >= 10000) { + throw new Error( + 'uuid.v1(): Can\'t create more than 10M uuids/sec'); + } + + _lastMSecs = msecs; + _lastNSecs = nsecs; + _clockseq = clockseq; + + // Per 4.1.4 - Convert from unix epoch to Gregorian epoch + msecs += 12219292800000; + + // `time_low` + var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000; + b[i++] = tl >>> 24 & 0xff; + b[i++] = tl >>> 16 & 0xff; + b[i++] = tl >>> 8 & 0xff; + b[i++] = tl & 0xff; + + // `time_mid` + var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff; + b[i++] = tmh >>> 8 & 0xff; + b[i++] = tmh & 0xff; + + // `time_high_and_version` + b[i++] = tmh >>> 24 & 0xf | 0x10; // include version + b[i++] = tmh >>> 16 & 0xff; + + // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant) + b[i++] = clockseq >>> 8 | 0x80; + + // `clock_seq_low` + b[i++] = clockseq & 0xff; + + // `node` + var node = options.node || _nodeId; + for (var n = 0; n < 6; n++) { + b[i + n] = node[n]; + } + + return buf ? buf : unparse(b); + } + + // **`v4()` - Generate random UUID** + + // See https://github.com/broofa/node-uuid for API details + function v4(options, buf, offset) { + // Deprecated - 'format' argument, as supported in v1.2 + var i = buf && offset || 0; + + if (typeof (options) === 'string') { + buf = (options === 'binary') ? new BufferClass(16) : null; + options = null; + } + options = options || {}; + + var rnds = options.random || (options.rng || _rng)(); + + // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` + rnds[6] = (rnds[6] & 0x0f) | 0x40; + rnds[8] = (rnds[8] & 0x3f) | 0x80; + + // Copy bytes to buffer, if provided + if (buf) { + for (var ii = 0; ii < 16; ii++) { + buf[i + ii] = rnds[ii]; } } - if (_window) { - setupBrowser(); - } else { - setupNode(); - } - - // Buffer class to use - var BufferClass = ('function' === typeof Buffer) ? Buffer : Array; - - // Maps for number <-> hex string conversion - var _byteToHex = []; - var _hexToByte = {}; - for (var i = 0; i < 256; i++) { - _byteToHex[i] = (i + 0x100).toString(16).substr(1); - _hexToByte[_byteToHex[i]] = i; - } - - // **`parse()` - Parse a UUID into it's component bytes** - function parse(s, buf, offset) { - var i = (buf && offset) || 0, - ii = 0; - - buf = buf || []; - s.toLowerCase().replace(/[0-9a-f]{2}/g, function (oct) { - if (ii < 16) { // Don't overflow! - buf[i + ii++] = _hexToByte[oct]; - } - }); - - // Zero out remaining bytes if string was short - while (ii < 16) { - buf[i + ii++] = 0; - } - - return buf; - } - - // **`unparse()` - Convert UUID byte array (ala parse()) into a string** - function unparse(buf, offset) { - var i = offset || 0, - bth = _byteToHex; - return bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]] + - bth[buf[i++]] + '-' + bth[buf[i++]] + bth[buf[i++]] + '-' + - bth[buf[i++]] + bth[buf[i++]] + '-' + bth[buf[i++]] + - bth[buf[i++]] + '-' + bth[buf[i++]] + bth[buf[i++]] + - bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]] + bth[buf[i++]]; - } - - // **`v1()` - Generate time-based UUID** - // - // Inspired by https://github.com/LiosK/UUID.js - // and http://docs.python.org/library/uuid.html - - // random #'s we need to init node and clockseq - var _seedBytes = _rng(); - - // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = - // 1) - var _nodeId = [ - _seedBytes[0] | 0x01, - _seedBytes[1], - _seedBytes[2], - _seedBytes[3], - _seedBytes[4], - _seedBytes[5] - ]; - - // Per 4.2.2, randomize (14 bit) clockseq - var _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff; - - // Previous uuid creation time - var _lastMSecs = 0, - _lastNSecs = 0; - - // See https://github.com/broofa/node-uuid for API details - function v1(options, buf, offset) { - var i = buf && offset || 0; - var b = buf || []; - - options = options || {}; - - var clockseq = (options.clockseq != null) ? options.clockseq : _clockseq; - - // UUID timestamps are 100 nano-second units since the Gregorian - // epoch, - // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so - // time is handled internally as 'msecs' (integer milliseconds) and - // 'nsecs' - // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 - // 00:00. - var msecs = (options.msecs != null) ? options.msecs : new Date() - .getTime(); - - // Per 4.2.1.2, use count of uuid's generated during the current - // clock - // cycle to simulate higher resolution clock - var nsecs = (options.nsecs != null) ? options.nsecs : _lastNSecs + 1; - - // Time since last uuid creation (in msecs) - var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs) / 10000; + return buf || unparse(rnds); + } - // Per 4.2.1.2, Bump clockseq on clock regression - if (dt < 0 && options.clockseq == null) { - clockseq = clockseq + 1 & 0x3fff; - } - - // Reset nsecs if clock regresses (new clockseq) or we've moved onto - // a new - // time interval - if ((dt < 0 || msecs > _lastMSecs) && options.nsecs == null) { - nsecs = 0; - } - - // Per 4.2.1.2 Throw error if too many uuids are requested - if (nsecs >= 10000) { - throw new Error( - 'uuid.v1(): Can\'t create more than 10M uuids/sec'); - } - - _lastMSecs = msecs; - _lastNSecs = nsecs; - _clockseq = clockseq; - - // Per 4.1.4 - Convert from unix epoch to Gregorian epoch - msecs += 12219292800000; - - // `time_low` - var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000; - b[i++] = tl >>> 24 & 0xff; - b[i++] = tl >>> 16 & 0xff; - b[i++] = tl >>> 8 & 0xff; - b[i++] = tl & 0xff; - - // `time_mid` - var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff; - b[i++] = tmh >>> 8 & 0xff; - b[i++] = tmh & 0xff; - - // `time_high_and_version` - b[i++] = tmh >>> 24 & 0xf | 0x10; // include version - b[i++] = tmh >>> 16 & 0xff; - - // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant) - b[i++] = clockseq >>> 8 | 0x80; - - // `clock_seq_low` - b[i++] = clockseq & 0xff; + // Export public API + var uuid = function () { + return new String(v4()); + }; + uuid.v1 = v1; + uuid.v4 = v4; + uuid.create = v4; + uuid.empty = "00000000-0000-0000-0000-000000000000"; + uuid.parse = parse; + uuid.unparse = unparse; + uuid.BufferClass = BufferClass; + uuid._rng = _rng; + uuid._mathRNG = _mathRNG; + uuid._nodeRNG = _nodeRNG; + uuid._whatwgRNG = _whatwgRNG; - // `node` - var node = options.node || _nodeId; - for (var n = 0; n < 6; n++) { - b[i + n] = node[n]; - } - - return buf ? buf : unparse(b); - } - - // **`v4()` - Generate random UUID** - - // See https://github.com/broofa/node-uuid for API details - function v4(options, buf, offset) { - // Deprecated - 'format' argument, as supported in v1.2 - var i = buf && offset || 0; - - if (typeof (options) === 'string') { - buf = (options === 'binary') ? new BufferClass(16) : null; - options = null; - } - options = options || {}; - - var rnds = options.random || (options.rng || _rng)(); - - // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` - rnds[6] = (rnds[6] & 0x0f) | 0x40; - rnds[8] = (rnds[8] & 0x3f) | 0x80; - - // Copy bytes to buffer, if provided - if (buf) { - for (var ii = 0; ii < 16; ii++) { - buf[i + ii] = rnds[ii]; - } - } - - return buf || unparse(rnds); - } - - // Export public API - var uuid = function () { - return new String(v4()); - }; - uuid.v1 = v1; - uuid.v4 = v4; - uuid.create = v4; - uuid.empty = "00000000-0000-0000-0000-000000000000"; - uuid.parse = parse; - uuid.unparse = unparse; - uuid.BufferClass = BufferClass; - uuid._rng = _rng; - uuid._mathRNG = _mathRNG; - uuid._nodeRNG = _nodeRNG; - uuid._whatwgRNG = _whatwgRNG; - - return uuid; - }); \ No newline at end of file + return uuid; +}); \ No newline at end of file diff -r 7d7059d2a810 -r 00779cb63b12 src/implab/components/ActivationController.js --- a/src/implab/components/ActivationController.js Fri Jun 02 19:28:20 2017 +0300 +++ b/src/implab/components/ActivationController.js Tue Jun 06 19:45:32 2017 +0300 @@ -1,55 +1,53 @@ -define([ "dojo/_base/declare", "../guard", "../safe", "../log/_LogMixin" ], - -function(declare, guard, safe, _LogMixin) { +define(["dojo/_base/declare", "../guard", "../safe", "../log/_LogMixin"], function (declare, guard, safe, _LogMixin) { "use strict"; - return declare([ _LogMixin ], { + return declare([_LogMixin], { - _current : null, + _current: null, - _pending : false, + _pending: false, - getCurrent : function() { + getCurrent: function () { return this._current; }, - _start : function() { + _start: function () { if (this._pending) throw new Error("The activation/decativation is already pending"); this._pending = true; }, - _await : function(d) { + _await: function (d) { var me = this; - return d.then(function(x) { + return d.then(function (x) { me._pending = false; return x; - }, function(e) { + }, function (e) { me._pending = false; throw e; }); }, - activate : function(component) { + activate: function (component) { safe.argumentNotNull(component, "component"); var me = this; if (component.getController() !== this) throw new Error("The specified component doesn't belong to this controller"); - return me._await(guard(me, "_start").then(function() { + return me._await(guard(me, "_start").then(function () { me._activate(component); })); }, - _activate : function(component) { + _activate: function (component) { var me = this; if (me._current === component) return guard(false); // before activation hook - return guard(me, "onActivating", [ component ]).then(function() { + return guard(me, "onActivating", [component]).then(function () { // deactivate curent if (me._current) - return me._current.deactivate(true).then(function() { + return me._current.deactivate(true).then(function () { try { me._current.onDeactivated(); } catch (err) { @@ -65,9 +63,9 @@ me._current = null; }); - }).then(function() { + }).then(function () { return component.activate(true); - }).then(function() { + }).then(function () { me._current = component; try { me.onActivated(component); @@ -86,21 +84,21 @@ * @returns true - компонента была деактивирована, либо нет активной * компоненты. false - запрос на деактивацию - отклонен. */ - deactivate : function() { + deactivate: function () { var me = this; - return me._await(guard(me,"_start").then(function() { + return me._await(guard(me, "_start").then(function () { return me._deactivate(); })); }, - _deactivate : function() { + _deactivate: function () { var me = this; if (!me._current) return guard(false); - return guard(me, "onDeactivating").then(function() { + return guard(me, "onDeactivating").then(function () { return me._current.deactivate(true); - }).then(function() { + }).then(function () { // HACK raise deactivated event try { me.onDeactivated(me._current); @@ -111,16 +109,12 @@ }); }, - onActivating : function(component) { - }, + onActivating: function (component) {}, - onDeactivating : function(component) { - }, + onDeactivating: function (component) {}, - onDeactivated : function(component, next) { - }, + onDeactivated: function (component, next) {}, - onActivated : function(component) { - } + onActivated: function (component) {} }); }); \ No newline at end of file diff -r 7d7059d2a810 -r 00779cb63b12 src/implab/components/ConsoleLogChannel.js --- a/src/implab/components/ConsoleLogChannel.js Fri Jun 02 19:28:20 2017 +0300 +++ b/src/implab/components/ConsoleLogChannel.js Tue Jun 06 19:45:32 2017 +0300 @@ -1,30 +1,26 @@ -define( - [ "dojo/_base/declare", "../text/format" ], - function(declare, format) { - return declare( - null, - { - name : null, +define(["dojo/_base/declare", "../text/format"], function (declare, format) { + return declare(null, { + name: null, - constructor : function(name) { - this.name = name; - }, + constructor: function (name) { + this.name = name; + }, + + log: function () { + console.log(this._makeMsg(arguments)); + }, - log : function() { - console.log(this._makeMsg(arguments)); - }, - - warn : function() { - console.warn(this._makeMsg(arguments)); - }, + warn: function () { + console.warn(this._makeMsg(arguments)); + }, - error : function() { - console.error(this._makeMsg(arguments)); - }, + error: function () { + console.error(this._makeMsg(arguments)); + }, - _makeMsg : function(args) { - return this.name ? this.name + " " + - format.apply(null, args) : format.apply(null, args); - } - }); - }); \ No newline at end of file + _makeMsg: function (args) { + return this.name ? this.name + " " + + format.apply(null, args) : format.apply(null, args); + } + }); +}); \ No newline at end of file diff -r 7d7059d2a810 -r 00779cb63b12 src/implab/components/_ActivatableMixin.js --- a/src/implab/components/_ActivatableMixin.js Fri Jun 02 19:28:20 2017 +0300 +++ b/src/implab/components/_ActivatableMixin.js Tue Jun 06 19:45:32 2017 +0300 @@ -1,40 +1,38 @@ -define([ "dojo/_base/declare", "../guard", "./StateMachine", "../log/_LogMixin", ], - -function(declare, guard, StateMachine, _LogMixin) { +define(["dojo/_base/declare", "../guard", "./StateMachine", "../log/_LogMixin", ], function (declare, guard, StateMachine, _LogMixin) { var states = { - inactive : { - activate : "activating" + inactive: { + activate: "activating" }, - activating : { - success : "active", - failed : "inactive" + activating: { + success: "active", + failed: "inactive" }, - active : { - deactivate : "deactivating" + active: { + deactivate: "deactivating" }, - deactivating : { - success : "inactive", - failed : "active" + deactivating: { + success: "inactive", + failed: "active" } }; - return declare([ _LogMixin ], { - _controller : null, + return declare([_LogMixin], { + _controller: null, - _active : null, + _active: null, - constructor : function() { + constructor: function () { this._active = new StateMachine({ - states : states, - initial : "inactive" + states: states, + initial: "inactive" }); }, /** * @returns {Object} контроллер для активации текущей компоненты */ - getController : function() { + getController: function () { return this._controller; }, @@ -42,18 +40,18 @@ * @param {Object} * v Контроллер для активации текущей компоненты */ - setController : function(v) { + setController: function (v) { this._controller = v; }, /** * @returns {Boolean} текущая компонента активна */ - isActive : function() { + isActive: function () { return this._active.current == "active"; }, - assertActive : function() { + assertActive: function () { if (!this.isActive()) throw new Error("The object must be active to perform the operation"); }, @@ -68,20 +66,20 @@ * контроллера. * @return{Boolean} успешно/неуспешно */ - activate : function(direct) { + activate: function (direct) { var me = this; if (!direct && this._controller) - return me._controller.activate(me).then(function() { + return me._controller.activate(me).then(function () { me.onActivated(); }); me._active.move("activate"); - return guard(me, "onActivating").then(function() { + return guard(me, "onActivating").then(function () { me.log("Activated"); me._active.move("success"); if (!me._controller) me.onActivated(); - }, function(err) { + }, function (err) { console.error(err); me.error("Activation failed: {0}", err); me._active.move("failed"); @@ -98,20 +96,20 @@ * участия контроллера. * */ - deactivate : function(direct) { + deactivate: function (direct) { var me = this; if (!direct && me._controller) - return me._controller.deactivate(me).then(function() { + return me._controller.deactivate(me).then(function () { me.onDeactivated(); }); me._active.move("deactivate"); - return guard(me, "onDeactivating").then(function() { + return guard(me, "onDeactivating").then(function () { me.log("Deactivated"); me._active.move("success"); if (!me._controller) me.onDeactivated(); - }, function(err) { + }, function (err) { console.error(err); me.error("Deactivation failed: {0}", err); me.move("failed"); @@ -120,9 +118,9 @@ }, - toogleActive : function() { + toogleActive: function () { var me = this; - return (me.isActive() ? me.deactivate() : me.activate()).then(function() { + return (me.isActive() ? me.deactivate() : me.activate()).then(function () { return me.isActive(); }); }, @@ -132,28 +130,24 @@ * * @returns{Boolean|undefined} если false - активация будет отменена */ - onActivating : function() { - }, + onActivating: function () {}, /** * Событие вызывается перед деактивацией текущей компоненты * * @returns {Boolean|undefined} если false - деактивация будет отменена */ - onDeactivating : function() { - }, + onDeactivating: function () {}, /** * Событие вызывается после активации текущей компоненты */ - onActivated : function() { - }, + onActivated: function () {}, /** * Событие вызывается после деактивации текущей компоненты */ - onDeactivated : function() { - } + onDeactivated: function () {} }); }); \ No newline at end of file diff -r 7d7059d2a810 -r 00779cb63b12 src/implab/components/_LogMixin.js --- a/src/implab/components/_LogMixin.js Fri Jun 02 19:28:20 2017 +0300 +++ b/src/implab/components/_LogMixin.js Tue Jun 06 19:45:32 2017 +0300 @@ -1,12 +1,12 @@ -define([ "dojo/_base/declare" ], - -function(declare) { +define([ + "implab/declare", "implab/declare/override" +], function (declare, override) { var cls = declare(null, { - _logChannel : null, + _logChannel: null, - _logLevel : 1, + _logLevel: 1, - constructor : function(opts) { + constructor: function (opts) { if (typeof opts == "object") { if ("logChannel" in opts) this._logChannel = opts.logChannel; @@ -15,31 +15,31 @@ } }, - getLogChannel : function() { + getLogChannel: function () { return this._logChannel; }, - setLogChannel : function(v) { + setLogChannel: function (v) { this._logChannel = v; }, - getLogLevel : function() { + getLogLevel: function () { return this._logLevel; }, - setLogLevel : function(v) { + setLogLevel: function (v) { this._logLevel = v; }, - log : function(format) { + log: function () { if (this._logChannel && this._logLevel > 2) this._logChannel.log.apply(this._logChannel, arguments); }, - warn : function(format) { + warn: function () { if (this._logChannel && this._logLevel > 1) this._logChannel.warn.apply(this._logChannel, arguments); }, - error : function(format) { + error: function () { if (this._logChannel && this._logLevel > 0) this._logChannel.error.apply(this._logChannel, arguments); }, @@ -47,21 +47,22 @@ /** * Used to by widgets */ - startup : function() { - var me = this, parent; + startup: override( /** @this */ function (inherited) { + var me = this, + parent; if (!me.getLogChannel()) { parent = me; - while (parent = parent.getParent()) { + while ((parent = parent.getParent())) { if (parent.getLogChannel) { me.setLogChannel(parent.getLogChannel()); - if(parent.getLogLevel) + if (parent.getLogLevel) me.setLogLevel(parent.getLogLevel()); break; } } } - this.inherited(arguments); - } + return inherited(); + }) }); return cls; }); \ No newline at end of file diff -r 7d7059d2a810 -r 00779cb63b12 src/implab/di/ActivationContext.js --- a/src/implab/di/ActivationContext.js Fri Jun 02 19:28:20 2017 +0300 +++ b/src/implab/di/ActivationContext.js Tue Jun 06 19:45:32 2017 +0300 @@ -60,7 +60,7 @@ clone: function () { return new Context( this.container, - safe.create(this._services), + Object.create(this._services), this._cache, this._visited ); @@ -123,7 +123,7 @@ scope: this._services }); if (localize) - this._services = safe.create(this._services); + this._services = Object.create(this._services); }, leave: function () { diff -r 7d7059d2a810 -r 00779cb63b12 src/implab/di/Container.js --- a/src/implab/di/Container.js Fri Jun 02 19:28:20 2017 +0300 +++ b/src/implab/di/Container.js Tue Jun 06 19:45:32 2017 +0300 @@ -29,7 +29,7 @@ constructor: function (parent) { this._parent = parent; - this._services = parent ? safe.create(parent._services) : {}; + this._services = parent ? Object.create(parent._services) : {}; this._cache = {}; this._cleanup = []; this._root = parent ? parent.getRootContainer() : this; diff -r 7d7059d2a810 -r 00779cb63b12 src/implab/di/ServiceDescriptor.js --- a/src/implab/di/ServiceDescriptor.js Fri Jun 02 19:28:20 2017 +0300 +++ b/src/implab/di/ServiceDescriptor.js Tue Jun 06 19:45:32 2017 +0300 @@ -218,7 +218,7 @@ }; } else if (this._params instanceof Array) { this._factory = function () { - var inst = safe.create(ctor.prototype); + var inst = Object.create(ctor.prototype); var ret = ctor.apply(inst, arguments); return typeof (ret) === "object" ? ret : inst; }; diff -r 7d7059d2a810 -r 00779cb63b12 src/implab/guard.js --- a/src/implab/guard.js Fri Jun 02 19:28:20 2017 +0300 +++ b/src/implab/guard.js Tue Jun 06 19:45:32 2017 +0300 @@ -1,4 +1,4 @@ -define([ "dojo/Deferred" ], function(Deferred) { +define([ "./Deferred" ], function(Deferred) { var toPromise = function(d) { if (d && d.then) return d; diff -r 7d7059d2a810 -r 00779cb63b12 src/implab/safe.js --- a/src/implab/safe.js Fri Jun 02 19:28:20 2017 +0300 +++ b/src/implab/safe.js Tue Jun 06 19:45:32 2017 +0300 @@ -1,84 +1,11 @@ define([], function () { - var id = 0, - OID_FIELD = "__core_safe_oid_field", - _create, _defineProperty, _keys; - - if (!Object.keys) { - _defineProperty = function (obj, prop, d) { - if (!d) - throw new Error("Invalid descriptor"); - obj[prop] = d.value; - }; - } else { - _defineProperty = Object.defineProperty; - } - - if (!Object.create) { - var tctor = function () {}; - _create = function (proto) { - if (arguments.length > 1) - throw new Error("The two arguments for isn't supported"); - - tctor.prototype = proto; - return new tctor(); - }; - } else { - _create = Object.create; - } - - if (!Object.keys) { - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys#Polyfill - _keys = (function () { - 'use strict'; - var hasOwnProperty = Object.prototype.hasOwnProperty, - hasDontEnumBug = !({ - toString: null - }).propertyIsEnumerable('toString'), - dontEnums = [ - 'toString', - 'toLocaleString', - 'valueOf', - 'hasOwnProperty', - 'isPrototypeOf', - 'propertyIsEnumerable', - 'constructor' - ], - dontEnumsLength = dontEnums.length; - - return function (obj) { - if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) { - throw new TypeError('Object.keys called on non-object'); - } - - var result = [], - prop, i; - - for (prop in obj) { - if (prop != OID_FIELD && hasOwnProperty.call(obj, prop)) { - result.push(prop); - } - } - - if (hasDontEnumBug) { - for (i = 0; i < dontEnumsLength; i++) { - if (hasOwnProperty.call(obj, dontEnums[i])) { - result.push(dontEnums[i]); - } - } - } - return result; - }; - }()); - } else { + var _create = Object.create, _keys = Object.keys; - } var safe = null; safe = { - OID_FIELD: OID_FIELD, - argumentNotNull: function (arg, name) { if (arg === null || arg === undefined) throw new Error("The argument " + name + " can't be null or undefined"); @@ -162,14 +89,6 @@ } }, - oid: function (obj) { - return this.isPrimitive(obj) ? undefined : obj[OID_FIELD] || - (_defineProperty(obj, OID_FIELD, { - value: ++id, - enumerable: false - }) && id); - }, - /** * Копирует свойства одного объекта в другой. * @@ -219,7 +138,11 @@ return dest; }, - create: _create, + create: function () { + if (console && console.warn) + console.warn("implab/safe::create is deprecated use Object.create instead"); + _create.apply(this, arguments); + }, delegate: function (target, method) { if (!(method instanceof Function)) { @@ -344,7 +267,7 @@ return cb ? cb(sequence[0]) : sequence[0]; } } - + if (err) return err(new Error("The sequence is required")); else