Skip to content

Commit

Permalink
Simplify how underscore.string is referred to.
Browse files Browse the repository at this point in the history
  • Loading branch information
cahrens authored and andy-armstrong committed Feb 24, 2016
1 parent 27b4402 commit 7e500f6
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 41 deletions.
2 changes: 1 addition & 1 deletion common/static/common/js/components/views/feedback_alert.js
Expand Up @@ -2,7 +2,7 @@
'use strict';
define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"],
function($, _, str, SystemFeedbackView) {
str = str || _.str;

var Alert = SystemFeedbackView.extend({
options: $.extend({}, SystemFeedbackView.prototype.options, {
type: "alert"
Expand Down
Expand Up @@ -2,7 +2,7 @@
'use strict';
define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"],
function($, _, str, SystemFeedbackView) {
str = str || _.str;

var Notification = SystemFeedbackView.extend({
options: $.extend({}, SystemFeedbackView.prototype.options, {
type: "notification",
Expand Down
Expand Up @@ -2,7 +2,7 @@
'use strict';
define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"],
function($, _, str, SystemFeedbackView) {
str = str || _.str;

var Prompt = SystemFeedbackView.extend({
options: $.extend({}, SystemFeedbackView.prototype.options, {
type: "prompt",
Expand Down
3 changes: 0 additions & 3 deletions common/static/common/js/utils/edx.utils.validate.js
Expand Up @@ -15,9 +15,6 @@
* by the access view, but doing it here helps keep the
* utility self-contained.
*/
if (_.isUndefined(_s)) {
_s = _.str;
}
_.mixin( _s.exports() );

utils = (function(){
Expand Down
1 change: 1 addition & 0 deletions lms/envs/common.py
Expand Up @@ -1219,6 +1219,7 @@
'js/vendor/jquery.cookie.js',
'js/vendor/url.min.js',
'js/vendor/underscore-min.js',
'js/vendor/underscore.string.min.js',
'js/vendor/require.js',
'js/RequireJS-namespace-undefine.js',
'js/vendor/URI.min.js',
Expand Down
1 change: 0 additions & 1 deletion lms/static/js/certificates/models/certificate_exception.js
Expand Up @@ -12,7 +12,6 @@
],

function(_, str, Backbone, gettext){
str = str || _.str;

return Backbone.Model.extend({
idAttribute: 'id',
Expand Down
Expand Up @@ -8,7 +8,6 @@
['underscore', 'underscore.string', 'gettext', 'backbone'],

function(_, str, gettext, Backbone) {
str = str || _.str;

return Backbone.Model.extend({
idAttribute: 'id',
Expand Down
24 changes: 7 additions & 17 deletions lms/static/js/spec/main.js
Expand Up @@ -181,22 +181,7 @@
},
'underscore': {
deps: ['underscore.string'],
exports: '_',
init: function(UnderscoreString) {
/* Mix non-conflicting functions from underscore.string
* (all but include, contains, and reverse) into the
* Underscore namespace. This allows the login, register,
* and password reset templates to render independent of the
* access view.
*/
_.mixin(UnderscoreString.exports());

/* Since the access view is not using RequireJS, we also
* expose underscore.string at _.str, so that the access
* view can perform the mixin on its own.
*/
_.str = UnderscoreString;
}
exports: '_'
},
'backbone': {
deps: ['underscore', 'jquery'],
Expand Down Expand Up @@ -370,7 +355,12 @@
},
'js/verify_student/views/step_view': {
exports: 'edx.verify_student.StepView',
deps: [ 'jquery', 'underscore', 'underscore.string', 'backbone', 'gettext' ]
deps: [ 'jquery', 'underscore', 'underscore.string', 'backbone', 'gettext' ],
init: function() {
// Set global variables that the payment code is expecting to be defined
window._ = require('underscore');
window._.str = require('underscore.string');
}
},
'js/verify_student/views/intro_step_view': {
exports: 'edx.verify_student.IntroStepView',
Expand Down
4 changes: 0 additions & 4 deletions lms/static/js/student_account/views/AccessView.js
Expand Up @@ -19,10 +19,6 @@
function($, utility, _, _s, Backbone, LoginModel, PasswordResetModel, RegisterModel, LoginView,
PasswordResetView, RegisterView, InstitutionLoginView, HintedLoginView) {

if (_.isUndefined(_s)) {
_s = _.str;
}

return Backbone.View.extend({
tpl: '#access-tpl',
events: {
Expand Down
13 changes: 5 additions & 8 deletions lms/static/js/verify_student/views/step_view.js
@@ -1,3 +1,5 @@
/*global jQuery, _, Backbone, gettext */

/**
* Base view for defining steps in the payment/verification flow.
*
Expand All @@ -8,7 +10,7 @@
*/
var edx = edx || {};

(function( $, _, _s, Backbone, gettext ) {
(function( $, _, Backbone, gettext ) {
'use strict';

edx.verify_student = edx.verify_student || {};
Expand All @@ -21,13 +23,8 @@
/* Mix non-conflicting functions from underscore.string
* (all but include, contains, and reverse) into the
* Underscore namespace.
*
* TODO: when running unit tests, _s is not defined. My first attempt at upgrading
* underscore.string did not solve this issue.
*/
if (_s) {
_.mixin(_s.exports());
}
_.mixin(_.str.exports());
},

render: function() {
Expand Down Expand Up @@ -106,4 +103,4 @@

});

})( jQuery, _, _.str, Backbone, gettext );
})( jQuery, _, Backbone, gettext );
1 change: 1 addition & 0 deletions lms/static/lms/js/build.js
Expand Up @@ -66,6 +66,7 @@
'jquery.url': 'empty:',
'backbone': 'empty:',
'underscore': 'empty:',
'underscore.string': 'empty:',
'logger': 'empty:',
'utility': 'empty:',
'URI': 'empty:',
Expand Down
6 changes: 6 additions & 0 deletions lms/static/lms/js/require-config.js
Expand Up @@ -19,6 +19,12 @@
};
defineDependency("jQuery", "jquery");
defineDependency("_", "underscore");
if (window._ && window._.str) {
define("underscore.string", [], function () {return window._.str;});
}
else {
console.error("Expected _.str (underscore.string) to be on the window object, but not found.");
}
defineDependency("gettext", "gettext");
defineDependency("Logger", "logger");
defineDependency("URI", "URI");
Expand Down
1 change: 0 additions & 1 deletion lms/templates/commerce/checkout_receipt.html
Expand Up @@ -19,7 +19,6 @@
</%block>
<%block name="js_extra">
<script src="${static.url('js/vendor/jquery.ajax-retry.js')}"></script>
<script src="${static.url('js/vendor/underscore.string.min.js')}"></script>
<script src="${static.url('js/src/tooltip_manager.js')}"></script>
<script src="${static.url('js/commerce/credit.js')}"></script>
<script src="${static.url('js/commerce/views/receipt_view.js')}"></script>
Expand Down
1 change: 0 additions & 1 deletion lms/templates/verify_student/incourse_reverify.html
Expand Up @@ -18,7 +18,6 @@
% endfor
</%block>
<%block name="js_extra">
<script src="${static.url('js/vendor/underscore.string.min.js')}"></script>
<script src="${static.url('js/src/tooltip_manager.js')}"></script>
<%static:js group='incourse_reverify'/>
</%block>
Expand Down
1 change: 0 additions & 1 deletion lms/templates/verify_student/pay_and_verify.html
Expand Up @@ -41,7 +41,6 @@
% endfor
</%block>
<%block name="js_extra">
<script src="${static.url('js/vendor/underscore.string.min.js')}"></script>
<script src="${static.url('js/src/tooltip_manager.js')}"></script>
<%static:js group='verify_student'/>
</%block>
Expand Down
1 change: 0 additions & 1 deletion lms/templates/verify_student/reverify.html
Expand Up @@ -16,7 +16,6 @@
% endfor
</%block>
<%block name="js_extra">
<script src="${static.url('js/vendor/underscore.string.min.js')}"></script>
<script src="${static.url('js/src/tooltip_manager.js')}"></script>
<%static:js group='reverify'/>
</%block>
Expand Down

0 comments on commit 7e500f6

Please sign in to comment.