Remove dependency management in supermodel.

This commit is contained in:
Ting-Kuan 2014-04-17 22:16:29 -04:00
parent 69fe4428e4
commit 64f986c286
3 changed files with 10 additions and 26 deletions

View file

@ -216,22 +216,11 @@ class ModelResource extends Resource
@isLoading = true
@loadDeferred = $.Deferred()
$.when.apply($, @loadDependencies())
.then(@onLoadDependenciesSuccess, @onLoadDependenciesFailed)
.always(=> @isLoading = false)
@fetchModel()
return @loadDeferred.promise()
loadDependencies: ->
promises = []
for dep in @dependencies
continue if not dep.isReadyForLoad()
promises.push(dep.load())
return promises
onLoadDependenciesSuccess: =>
fetchModel: ->
@model.fetch(@fetchOptions)
###
@ -253,11 +242,6 @@ class ModelResource extends Resource
@loadDeferred.reject(@)
)
onLoadDependenciesFailed: =>
@markFailed('Failed to load dependencies.')
@loadDeferred.reject(@)
class RequestResource extends Resource
constructor: (name, jqxhrOptions, value) ->
super(name, value)

View file

@ -21,13 +21,13 @@ module.exports = class PatchesView extends CocoView
@startedLoading = false
@patches = new PatchesCollection([], {}, @model, @status)
@patchesRes = @supermodel.addModelResource(@patches, 'patches')
@patchesRes.load()
load: ->
return unless @patchesRes.loaded
ids = (p.get('creator') for p in @patches.models)
jqxhrOptions = nameLoader.loadNames ids
@nameLoaderRes = @supermodel.addRequestResource('name_loader', jqxhrOptions)
@nameLoaderRes.addDependency(@patchesRes)
load: ->
@nameLoaderRes.load()
getRenderData: ->

View file

@ -49,8 +49,7 @@ module.exports = class ThangTypeEditView extends View
@thangType = new ThangType(_id: @thangTypeID)
@thangType.saveBackups = true
@listenToOnce(@thangType, 'error',
() =>
@listenToOnce(@thangType, 'error', =>
@hideLoading()
# Hack: editor components appear after calling insertSubView.
@ -61,10 +60,11 @@ module.exports = class ThangTypeEditView extends View
)
thangRes = @supermodel.addModelResource(@thangType, 'thang_type')
thangRes.load()
@files = new DocumentFiles(@thangType)
thangDocRes = @supermodel.addModelResource(@files, 'thang_document')
thangRes.addDependency(thangDocRes)
thangRes.load()
thangDocRes.load()
@refreshAnimation = _.debounce @refreshAnimation, 500