removed 6 underscore requires

This commit is contained in:
Peter Cottle 2015-04-20 16:19:15 +10:00
parent b5cf7f9343
commit 93d9ac693f
11 changed files with 48 additions and 31 deletions

View file

@ -251,7 +251,7 @@ module.exports = function(grunt) {
grunt.registerTask('watching', ['fastBuild', 'jasmine_node', 'jshint', 'lintStrings']); grunt.registerTask('watching', ['fastBuild', 'jasmine_node', 'jshint', 'lintStrings']);
grunt.registerTask('default', ['build']); grunt.registerTask('default', ['build']);
grunt.registerTask('test', ['jasmine_node', 'shell:casperTest']); grunt.registerTask('test', ['jasmine_node']);
grunt.registerTask('casperTest', ['shell:casperTest']); grunt.registerTask('casperTest', ['shell:casperTest']);
}; };

View file

@ -1,7 +1,8 @@
var _ = require('underscore');
var Backbone = require('backbone'); var Backbone = require('backbone');
var EventEmitter = require('events').EventEmitter;
var React = require('react'); var React = require('react');
var assign = require('object-assign');
var util = require('../util'); var util = require('../util');
var intl = require('../intl'); var intl = require('../intl');
var LocaleStore = require('../stores/LocaleStore'); var LocaleStore = require('../stores/LocaleStore');
@ -10,7 +11,16 @@ var LocaleActions = require('../actions/LocaleActions');
/** /**
* Globals * Globals
*/ */
var events = _.clone(Backbone.Events); var events = assign(
{},
EventEmitter.prototype,
{
trigger: function() {
// alias this for backwards compatibility
this.emit.apply(this, arguments);
}
}
);
var commandUI; var commandUI;
var sandbox; var sandbox;
var eventBaton; var eventBaton;
@ -118,7 +128,7 @@ var initRootEvents = function(eventBaton) {
var makeKeyListener = function(name) { var makeKeyListener = function(name) {
return function() { return function() {
var args = [name]; var args = [name];
_.each(arguments, function(arg) { Array.prototype.slice.apply(arguments).forEach(function(arg) {
args.push(arg); args.push(arg);
}); });
eventBaton.trigger.apply(eventBaton, args); eventBaton.trigger.apply(eventBaton, args);

View file

@ -1,5 +1,3 @@
var _ = require('underscore');
var toGlobalize = { var toGlobalize = {
App: require('../app/index.js'), App: require('../app/index.js'),
Tree: require('../visuals/tree'), Tree: require('../visuals/tree'),
@ -37,7 +35,9 @@ var toGlobalize = {
Intl: require('../intl') Intl: require('../intl')
}; };
_.each(toGlobalize, function(module, moduleName) { Object.keys(toGlobalize).forEach(function(moduleName) {
var module = toGlobalize[moduleName];
for (var key in module) { for (var key in module) {
var value = module[key]; var value = module[key];
if (value instanceof Function) { if (value instanceof Function) {
@ -53,7 +53,6 @@ $(document).ready(function() {
window.debug_sandbox = toGlobalize.Main.getSandbox(); window.debug_sandbox = toGlobalize.Main.getSandbox();
window.debug_modules = toGlobalize; window.debug_modules = toGlobalize;
window.debug_levelDropdown = toGlobalize.Main.getLevelDropdown(); window.debug_levelDropdown = toGlobalize.Main.getLevelDropdown();
window.debug_under = _;
window.debug_copyTree = function() { window.debug_copyTree = function() {
return toGlobalize.Main.getSandbox().mainVis.gitEngine.printAndCopyTree(); return toGlobalize.Main.getSandbox().mainVis.gitEngine.printAndCopyTree();
}; };

View file

@ -1,17 +1,18 @@
var _ = require('underscore');
var Backbone = require('backbone'); var Backbone = require('backbone');
var MyError = Backbone.Model.extend({ var MyError = Backbone.Model.extend({
defaults: { defaults: {
type: 'MyError', type: 'MyError'
msg: 'Unknown Error'
}, },
toString: function() { toString: function() {
return this.get('type') + ': ' + this.get('msg'); return this.get('type') + ': ' + this.get('msg');
}, },
getMsg: function() { getMsg: function() {
return this.get('msg') || 'Unknown Error'; if (!this.get('msg')) {
console.warn('mye rror without message');
}
return this.get('msg');
} }
}); });

View file

@ -0,0 +1,14 @@
var mapping = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
'/': '&#x2F;'
};
module.exports = function(string) {
return ('' + string).replace(/[&<>"'\/]/g, function(match) {
return mapping[match];
});
};

View file

@ -1,5 +1,3 @@
var _ = require('underscore');
function EventBaton(options) { function EventBaton(options) {
this.eventMap = {}; this.eventMap = {};
this.options = options || {}; this.options = options || {};
@ -70,13 +68,13 @@ EventBaton.prototype.passBatonBack = function(name, func, context, args) {
var listeners = this.getListenersThrow(name); var listeners = this.getListenersThrow(name);
var indexBefore; var indexBefore;
_.each(listeners, function(listenerObj, index) { listeners.forEach(function(listenerObj, index) {
// skip the first // skip the first
if (index === 0) { return; } if (index === 0) { return; }
if (listenerObj.func === func && listenerObj.context === context) { if (listenerObj.func === func && listenerObj.context === context) {
indexBefore = index - 1; indexBefore = index - 1;
} }
}, this); });
if (indexBefore === undefined) { if (indexBefore === undefined) {
throw new Error('you are the last baton holder! or i didnt find you'); throw new Error('you are the last baton holder! or i didnt find you');
} }
@ -92,7 +90,7 @@ EventBaton.prototype.releaseBaton = function(name, func, context) {
var newListeners = []; var newListeners = [];
var found = false; var found = false;
_.each(listeners, function(listenerObj) { listeners.forEach(function(listenerObj) {
if (listenerObj.func === func && listenerObj.context === context) { if (listenerObj.func === func && listenerObj.context === context) {
if (found) { if (found) {
console.warn('woah duplicates!!!'); console.warn('woah duplicates!!!');
@ -102,7 +100,7 @@ EventBaton.prototype.releaseBaton = function(name, func, context) {
} else { } else {
newListeners.push(listenerObj); newListeners.push(listenerObj);
} }
}, this); });
if (!found) { if (!found) {
console.log('did not find that function', func, context, name, arguments); console.log('did not find that function', func, context, name, arguments);
@ -113,4 +111,3 @@ EventBaton.prototype.releaseBaton = function(name, func, context) {
}; };
exports.EventBaton = EventBaton; exports.EventBaton = EventBaton;

View file

@ -1,4 +1,4 @@
var _ = require('underscore'); var escapeString = require('../util/escapeString');
var constants = require('../util/constants'); var constants = require('../util/constants');
exports.parseQueryString = function(uri) { exports.parseQueryString = function(uri) {
@ -17,9 +17,9 @@ exports.isBrowser = function() {
}; };
exports.splitTextCommand = function(value, func, context) { exports.splitTextCommand = function(value, func, context) {
func = _.bind(func, context); func = func.bind(context);
_.each(value.split(';'), function(command, index) { value.split(';').forEach(function(command, index) {
command = _.escape(command); command = escapeString(command);
command = command command = command
.replace(/^(\s+)/, '') .replace(/^(\s+)/, '')
.replace(/(\s+)$/, '') .replace(/(\s+)$/, '')
@ -38,8 +38,8 @@ exports.genParseCommand = function(regexMap, eventName) {
var method; var method;
var regexResults; var regexResults;
_.each(regexMap, function(regex, _method) { Object.keys(regexMap).forEach(function(_method) {
var results = regex.exec(str); var results = regexMap[_method].exec(str);
if (results) { if (results) {
method = _method; method = _method;
regexResults = results; regexResults = results;

View file

@ -1,4 +1,3 @@
var _ = require('underscore');
var Backbone = require('backbone'); var Backbone = require('backbone');
var Main = require('../app'); var Main = require('../app');
@ -17,7 +16,7 @@ var mapKeycodeToKey = function(keycode) {
}; };
function KeyboardListener(options) { function KeyboardListener(options) {
this.events = options.events || _.clone(Backbone.Events); this.events = options.events;
this.aliasMap = options.aliasMap || {}; this.aliasMap = options.aliasMap || {};
if (!options.wait) { if (!options.wait) {

View file

@ -1,5 +1,3 @@
var _ = require('underscore');
var _warnOnce = true; var _warnOnce = true;
function detectZoom() { function detectZoom() {
/** /**

View file

@ -113,7 +113,7 @@ var CommandPromptView = Backbone.View.extend({
// 10px for monospaced font at "1" zoom // 10px for monospaced font at "1" zoom
var zoom = require('../util/zoomLevel').detectZoom(); var zoom = require('../util/zoomLevel').detectZoom();
var widthPerChar = 10 * zoom; var widthPerChar = 9.65 * zoom;
var heightPerRow = 22 * zoom; var heightPerRow = 22 * zoom;
var widthOfParagraph = $(this.commandParagraph).width(); var widthOfParagraph = $(this.commandParagraph).width();

View file

@ -442,7 +442,6 @@ div.controls div.box.flex1 div.plus {
} }
/* Command Line */ /* Command Line */
div.reactCommandView p.commandLine i { div.reactCommandView p.commandLine i {
margin: 0 5px; margin: 0 5px;
} }