Fixed a terrible bug.

This commit is contained in:
Scott Erickson 2014-08-22 11:40:31 -07:00
parent e200889f0b
commit f15135efe1

View file

@ -25,6 +25,7 @@ module.exports = class ThangComponentsEditView extends CocoView
constructor: (options) -> constructor: (options) ->
super options super options
@originalsLoaded = {}
@components = options.components or [] @components = options.components or []
@components = $.extend true, [], @components # just to be sure @components = $.extend true, [], @components # just to be sure
@lastComponentLength = @components.length @lastComponentLength = @components.length
@ -36,6 +37,10 @@ module.exports = class ThangComponentsEditView extends CocoView
loadComponents: (components) -> loadComponents: (components) ->
for componentRef in components for componentRef in components
# just to handle if ever somehow the same component is loaded twice, through bad data and alike
continue if @originalsLoaded[componentRef.original]
@originalsLoaded[componentRef.original] = componentRef.original
levelComponent = new LevelComponent(componentRef) levelComponent = new LevelComponent(componentRef)
url = "/db/level.component/#{componentRef.original}/version/#{componentRef.majorVersion}" url = "/db/level.component/#{componentRef.original}/version/#{componentRef.majorVersion}"
levelComponent.setURL(url) levelComponent.setURL(url)
@ -143,7 +148,9 @@ module.exports = class ThangComponentsEditView extends CocoView
@reportChanges() @reportChanges()
updateComponentsList: -> updateComponentsList: ->
@componentsTreema?.set('/', $.extend(true, [], @components)) # Before I was setting the data to the existing treema but then we had some
# nasty sorting/callback bugs. This is less efficient, but it's also less bug prone.
@buildComponentsTreema()
onComponentsAdded: -> onComponentsAdded: ->
return unless @componentsTreema return unless @componentsTreema
@ -157,11 +164,14 @@ module.exports = class ThangComponentsEditView extends CocoView
for componentRef in _.values(componentMap) for componentRef in _.values(componentMap)
componentModel = @supermodel.getModelByOriginalAndMajorVersion( componentModel = @supermodel.getModelByOriginalAndMajorVersion(
LevelComponent, componentRef.original, componentRef.majorVersion) LevelComponent, componentRef.original, componentRef.majorVersion)
if not componentModel?.loaded
@loadComponents([componentRef])
continue
for dependency in componentModel?.get('dependencies') or [] for dependency in componentModel?.get('dependencies') or []
if not componentMap[dependency.original] if not componentMap[dependency.original]
component = @supermodel.getModelByOriginalAndMajorVersion( component = @supermodel.getModelByOriginalAndMajorVersion(
LevelComponent, dependency.original, dependency.majorVersion) LevelComponent, dependency.original, dependency.majorVersion)
if not component if not component?.loaded
@loadComponents([dependency]) @loadComponents([dependency])
# will run onComponentsAdded once more when the model loads # will run onComponentsAdded once more when the model loads
else else
@ -204,7 +214,7 @@ module.exports = class ThangComponentsEditView extends CocoView
makeThangComponentConfigView: (thangComponent) -> makeThangComponentConfigView: (thangComponent) ->
component = @supermodel.getModelByOriginal(LevelComponent, thangComponent.original) component = @supermodel.getModelByOriginal(LevelComponent, thangComponent.original)
return unless component return unless component?.loaded
config = thangComponent.config ? {} config = thangComponent.config ? {}
configView = new ThangComponentConfigView({ configView = new ThangComponentConfigView({
supermodel: @supermodel supermodel: @supermodel