Refactored away from having the underscore string library added to the String prototype.

This commit is contained in:
Scott Erickson 2015-01-04 08:05:38 -08:00
parent 94a1b3c06f
commit 1446f77a17
15 changed files with 18 additions and 18 deletions

View file

@ -107,7 +107,7 @@ module.exports = class CocoRouter extends Backbone.Router
window.location.href = window.location.href
routeDirectly: (path, args) ->
path = "views/#{path}" if not _.str.startsWith(path, 'views/')
path = "views/#{path}" if not _.string.startsWith(path, 'views/')
ViewClass = @tryToLoadModule path
if not ViewClass and application.moduleLoader.load(path)
@listenToOnce application.moduleLoader, 'load-complete', ->

View file

@ -118,7 +118,7 @@ module.exports.getConflicts = (headDeltas, pendingDeltas) ->
offset += 1
# these stop being substrings of each other? Then conflict DNE
if not (nextPath.startsWith path) then break
if not (_.string.startsWith nextPath, path) then break
# check if these two are from the same group, but we still need to check for more beyond
unless headPathMap[path] or headPathMap[nextPath] then continue

View file

@ -25,8 +25,8 @@ init = ->
watchForErrors()
setUpIOSLogging()
path = document.location.pathname
app.testing = path.startsWith '/test'
app.demoing = path.startsWith '/demo'
app.testing = _.string.startsWith path, '/test'
app.demoing = _.string.startsWith path, '/demo'
initializeUtilityServices() unless app.testing or app.demoing
setUpBackboneMediator()
app.initialize()

View file

@ -197,7 +197,7 @@ module.exports = Lank = class Lank extends CocoClass
showAreaOfEffects: ->
return unless @thang?.currentEvents
for event in @thang.currentEvents
continue unless event.startsWith 'aoe-'
continue unless _.string.startsWith event, 'aoe-'
continue if @handledDisplayEvents[event]
@handledDisplayEvents[event] = true
args = JSON.parse(event[4...])
@ -240,7 +240,7 @@ module.exports = Lank = class Lank extends CocoClass
showTextEvents: ->
return unless @thang?.currentEvents
for event in @thang.currentEvents
continue unless event.startsWith 'text-'
continue unless _.string.startsWith event, 'text-'
continue if @handledDisplayEvents[event]
@handledDisplayEvents[event] = true
options = JSON.parse(event[5...])

View file

@ -199,7 +199,7 @@ module.exports = LayerAdapter = class LayerAdapter extends CocoClass
@upsertActionToRender(lank.thangType)
else
for action in _.values(lank.thangType.getActions())
continue unless _.any @defaultActions, (prefix) -> action.name.startsWith(prefix)
continue unless _.any @defaultActions, (prefix) -> _.string.startsWith(action.name, prefix)
@upsertActionToRender(lank.thangType, action.name, lank.options.colorConfig)
upsertActionToRender: (thangType, actionName, colorConfig) ->

View file

@ -38,7 +38,7 @@ module.exports = class SegmentedSprite extends createjs.SpriteContainer
@actionNotSupported = false
action = @thangType.getActions()[actionName]
randomStart = actionName.startsWith('move')
randomStart = _.string.startsWith(actionName, 'move')
# because the resulting segmented image is set to the size of the movie clip, you can use
# the raw registration data without scaling it.

View file

@ -20,7 +20,7 @@ module.exports = class SingularSprite extends createjs.Sprite
@actionNotSupported = false
action = @thangType.getActions()[actionName]
randomStart = actionName.startsWith('move')
randomStart = _.string.startsWith(actionName, 'move')
reg = action.positions?.registration or @thangType.get('positions')?.registration or {x:0, y:0}
if action.animation

View file

@ -291,7 +291,7 @@ module.exports = class ThangType extends CocoModel
uploadGenericPortrait: (callback, src) ->
src ?= @getPortraitSource()
return callback?() unless src and src.startsWith 'data:'
return callback?() unless src and _.string.startsWith src, 'data:'
src = src.replace('data:image/png;base64,', '').replace(/\ /g, '+')
body =
filename: 'portrait.png'

View file

@ -68,7 +68,7 @@ module.exports = DemoView = class DemoView extends RootView
@demoFiles = @getAllDemoFiles()
if @subPath
prefix = DEMO_REQUIRE_PREFIX + @subPath
@demoFiles = (f for f in @demoFiles when f.startsWith prefix)
@demoFiles = (f for f in @demoFiles when _.string.startsWith f, prefix)
runDemo: ->
# TODO: Maybe have an option to run all demos in this folder at the same time?

View file

@ -27,7 +27,7 @@ module.exports = class HomeView extends RootView
c.isOldBrowser = true if $.browser.safari && majorVersion < 6 # 6 might have problems with Aether, or maybe just old minors of 6: https://errorception.com/projects/51a79585ee207206390002a2/errors/547a202e1ead63ba4e4ac9fd
else
console.warn 'no more jquery browser version...'
c.isEnglish = (me.get('preferredLanguage') or 'en').startsWith 'en'
c.isEnglish = _.string.startsWith (me.get('preferredLanguage') or 'en'), 'en'
c.languageName = me.get('preferredLanguage')
c.explainsHourOfCode = @explainsHourOfCode
c.isMobile = @isMobile()

View file

@ -42,7 +42,7 @@ module.exports = TestView = class TestView extends RootView
@specFiles = TestView.getAllSpecFiles()
if @subPath
prefix = TEST_REQUIRE_PREFIX + @subPath
@specFiles = (f for f in @specFiles when f.startsWith prefix)
@specFiles = (f for f in @specFiles when _.string.startsWith f, prefix)
@runTests: (specFiles) ->
specFiles ?= @getAllSpecFiles()

View file

@ -544,7 +544,7 @@ module.exports = class ThangTypeEditView extends RootView
return @stopShowingSelectedNode() if not selected
path = selected.getPath()
parts = path.split('/')
return @stopShowingSelectedNode() unless parts.length >= 4 and path.startsWith '/raw/'
return @stopShowingSelectedNode() unless parts.length >= 4 and _.string.startsWith path, '/raw/'
key = parts[3]
type = parts[2]
vectorParser = new SpriteBuilder(@thangType)

View file

@ -72,10 +72,10 @@ module.exports = class I18NHomeView extends RootView
updateCoverage: ->
selectedBase = @selectedLanguage[..2]
relatedLanguages = (l for l in languages when l.startsWith(selectedBase) and l isnt @selectedLanguage)
relatedLanguages = (l for l in languages when _.string.startsWith(l, selectedBase) and l isnt @selectedLanguage)
for model in @aggregateModels.models
@updateCoverageForModel(model, relatedLanguages)
model.generallyCovered = true if @selectedLanguage.startsWith 'en'
model.generallyCovered = true if _.string.startsWith @selectedLanguage, 'en'
@aggregateModels.sort()
updateCoverageForModel: (model, relatedLanguages) ->

View file

@ -98,7 +98,7 @@ module.exports = class LadderView extends RootView
onClickedLink: (e) ->
link = $(e.target).closest('a').attr('href')
if link?.startsWith('/play/level') and me.get('anonymous')
if link? and _.string.startsWith(link, '/play/level') and me.get('anonymous')
e.stopPropagation()
e.preventDefault()
@showApologeticSignupModal()

View file

@ -529,7 +529,7 @@ getJasmineRequireObj().AjaxRequestTracker = function() {
var requests = jasmine.Ajax.requests.all().slice();
for(var j in requests) {
var request = requests[j];
if(request.url.startsWith(url)) {
if(_.string.startsWith(request.url, url)) {
request.respondWith({status: 200, responseText: JSON.stringify(responseBody)});
responded = true;
break;