Skip to content

Commit

Permalink
0.2.1 milo.util.deprecate; deprecated methods will log error
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Mar 2, 2015
1 parent ec1311f commit 5502bb0
Show file tree
Hide file tree
Showing 19 changed files with 428 additions and 327 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module.exports = function(grunt) {
grunt.registerTask('karmatest', 'karma');
grunt.registerTask('htmltest', ['browserify:test1', 'watch']);
grunt.registerTask('tests', ['mochaTest', 'browserify', 'karmatest']);
grunt.registerTask('default', ['test', 'browserify', 'exorcise', 'watch']);
grunt.registerTask('default', ['test', 'browserify', 'uglify', 'exorcise', 'watch']);
grunt.registerTask('skiptest', ['browserify', 'watch']);

};
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "milo",
"version": "0.2.0",
"version": "0.2.1",
"homepage": "https://github.com/milojs/milo",
"authors": [
"MOL Technical <[email protected]>"
Expand Down
4 changes: 2 additions & 2 deletions lib/components/ui/FoldTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var doT = require('milo-core').util.doT
, componentsRegistry = require('../c_registry')
, Component = require('../c_class')
, miloCount = require('../../util/count');
, uniqueId = require('../../util/unique_id');

var TREE_TEMPLATE = '<ul class="ml-ui-foldtree-list">\
{{~ it.data.items :item:index }}\
Expand Down Expand Up @@ -87,7 +87,7 @@ function MLFoldTree$renderTree (data) {
function _renderTree (data) {
if (data.items)
var itemsIDs = _.map(data.items, function(item) {
var id = miloCount();
var id = uniqueId();
self._itemsMap[id] = item;
return id;
});
Expand Down
4 changes: 2 additions & 2 deletions lib/components/ui/RadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var Component = require('../c_class')
, componentsRegistry = require('../c_registry')
, miloCount = require('../../util/count')
, uniqueId = require('../../util/unique_id')
, _ = require('milo-core').proto;


Expand Down Expand Up @@ -61,7 +61,7 @@ _.extendProto(MLRadioGroup, {
*/
function MLRadioGroup$init() {
_.defineProperty(this, '_radioList', [], _.CONF);
_.defineProperty(this, ELEMENT_NAME_PROPERTY, ELEMENT_NAME_PREFIX + miloCount());
_.defineProperty(this, ELEMENT_NAME_PROPERTY, ELEMENT_NAME_PREFIX + uniqueId());
this._renderOptions = {};
Component.prototype.init.apply(this, arguments);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ config({
timeout: 15000,
responsePrefix: 'response_'
}
}
},
deprecationWarning: 'once'
});
2 changes: 1 addition & 1 deletion lib/milo.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ _.extend(milo, {
Component: require('./components/c_class'),
Command: require('./command'),
registry: require('./registry'),
milo_version: '0.2.0',
milo_version: '0.2.1',
createComponentClass: require('./util/create_component_class'),
destroy: destroy
});
Expand Down
4 changes: 2 additions & 2 deletions lib/util/component_name.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var count = require('./count')
var uniqueId = require('./unique_id')
, config = require('../config')
, prefix = config.componentPrefix;

Expand All @@ -9,5 +9,5 @@ module.exports = componentName;


function componentName() {
return prefix + count();
return prefix + uniqueId();
}
32 changes: 32 additions & 0 deletions lib/util/deprecate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';


var miloCore = require('milo-core')
, _ = miloCore.proto
, logger = miloCore.util.logger
, config = require('../config');


module.exports = function deprecate(fn, message) {
var warned;
switch (typeof fn) {
case 'object':
return _.mapKeys(fn, function(f) { return deprecate(f, message); });
case 'function':
for (var prop in fn)
deprecated[prop] = deprecate(fn[prop], message);
return deprecated;
default:
return fn;
}


function deprecated() {
if (config.deprecationWarning
&& (!warned || config.deprecationWarning == 'always')) {
logger.error(message || 'Function ' + fn.name + ' is DEPRECATED');
warned = true;
}
return fn.apply(this, arguments);
}
};
18 changes: 11 additions & 7 deletions lib/util/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var miloCore = require('milo-core');
var miloCore = require('milo-core')
, deprecate = require('./deprecate');

/**
* `milo.util`
Expand All @@ -10,20 +11,23 @@ var util = {
request: require('./request'),
websocket: require('./websocket'),
check: miloCore.util.check,
error: require('./error'), // deprecated
count: require('./count'), // deprecated
uniqueId: require('./count'),
error: deprecate(require('./error'), 'milo.util.error is DEPRECATED and will be REMOVED soon!'),
count: deprecate(require('./unique_id'), 'milo.util.count is DEPRECATED! Use milo.util.uniqueId instead'),
uniqueId: require('./unique_id'),
componentName: require('./component_name'),
dom: require('./dom'),
domListeners: require('./dom_listeners'),
selection: require('./selection'),
fragment: require('./fragment'),
jsonParse: require('./json_parse'), // deprecated
jsonParse: deprecate(require('./json_parse'), 'milo.util.jsonParse is DEPRECATED! Use _.jsonParse instead'),
storage: require('./storage'),
domReady: require('./domready'),
dragDrop: require('./dragdrop'),
dialog: require('../components/ui/bootstrap/Dialog'), // deprecated - should be used from registry
alert: require('../components/ui/bootstrap/Alert'), // deprecated - should be used from registry
dialog: deprecate(require('../components/ui/bootstrap/Dialog'),
'milo.util.dialog is DEPRECATED! Use milo.registry.components.get(\'MLDialog\') instead'),
alert: deprecate(require('../components/ui/bootstrap/Alert'),
'milo.util.alert is DEPRECATED! Use milo.registry.components.get(\'MLAlert\') instead'),
deprecate: deprecate,
doT: miloCore.util.doT,
destroy: util_destroy
};
Expand Down
4 changes: 2 additions & 2 deletions lib/util/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

var miloCore = require('milo-core')
, _ = miloCore.proto
, count = require('./count')
, uniqueId = require('./unique_id')
, config = require('../config')
, logger = miloCore.util.logger
, Messenger = miloCore.Messenger;
Expand Down Expand Up @@ -206,7 +206,7 @@ function request$jsonp(url, callback) {
var script = document.createElement('script'),
xPromise = _createXPromise(script),
head = window.document.head,
uniqueCallback = config.request.jsonpCallbackPrefix + count();
uniqueCallback = config.request.jsonpCallbackPrefix + uniqueId();

var opts = _.extend({ url: url }, jsonpOptions);
if (_messenger) request.postMessageSync('request', { options: opts });
Expand Down
4 changes: 2 additions & 2 deletions lib/util/storage/msg_src.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var miloCore = require('milo-core')
, MessageSource = miloCore.classes.MessageSource
, _ = miloCore.proto
, config = require('../../config')
, miloCount = require('../../util/count');
, uniqueId = require('../../util/unique_id');

var StorageMessageSource = _.createSubclass(MessageSource, 'StorageMessageSource', true);

Expand Down Expand Up @@ -53,7 +53,7 @@ function StorageMessageSource$postMessage(message, data) {
function StorageMessageSource$trigger(msgType, data) {
var key = this.messageKey + msgType;
data = data || {};
data[config.domStorage.messageTimestamp] = miloCount();
data[config.domStorage.messageTimestamp] = uniqueId();
_.deferMethod(this.storage, 'setItem', key, data);
}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/util/websocket/msg_src.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var miloCore = require('milo-core')
, MessageSource = miloCore.classes.MessageSource
, _ = miloCore.proto
, logger = miloCore.util.logger
, uniqueId = require('../../util/count')
, uniqueId = require('../../util/unique_id')
, config = require('../../config')
, check = miloCore.util.check
, Match = check.Match;
Expand Down
Loading

0 comments on commit 5502bb0

Please sign in to comment.