mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 16:17:57 -05:00
More memory fixes.
This commit is contained in:
parent
71b6ebf8eb
commit
bdbb1710eb
1 changed files with 12 additions and 6 deletions
|
@ -8,8 +8,8 @@ class SuperModel
|
|||
@mustPopulate = model
|
||||
model.saveBackups = @shouldSaveBackups(model)
|
||||
model.fetch() unless model.loaded or model.loading
|
||||
model.on('sync', @modelLoaded) unless model.loaded
|
||||
model.once('error', @modelErrored) unless model.loaded
|
||||
model.on('sync', @modelLoaded, @) unless model.loaded
|
||||
model.once('error', @modelErrored, @) unless model.loaded
|
||||
url = model.url()
|
||||
@models[url] = model unless @models[url]?
|
||||
@modelLoaded(model) if model.loaded
|
||||
|
@ -18,12 +18,13 @@ class SuperModel
|
|||
shouldPopulate: (url) -> return true
|
||||
shouldSaveBackups: (model) -> return false
|
||||
|
||||
modelErrored: (model) =>
|
||||
modelErrored: (model) ->
|
||||
@trigger 'error'
|
||||
@removeEventsFromModel(model)
|
||||
|
||||
modelLoaded: (model) =>
|
||||
modelLoaded: (model) ->
|
||||
schema = model.schema()
|
||||
return schema.on('sync', => @modelLoaded(model)) unless schema.loaded
|
||||
return schema.once('sync', => @modelLoaded(model)) unless schema.loaded
|
||||
refs = model.getReferencedModels(model.attributes, schema.attributes)
|
||||
refs = [] unless @mustPopulate is model or @shouldPopulate(model)
|
||||
# console.log 'Loaded', model.get('name')
|
||||
|
@ -33,10 +34,15 @@ class SuperModel
|
|||
continue if @models[refURL]
|
||||
@models[refURL] = ref
|
||||
ref.fetch()
|
||||
ref.on 'sync', @modelLoaded
|
||||
ref.on 'sync', @modelLoaded, @
|
||||
|
||||
@trigger 'loaded-one', model: model
|
||||
@trigger 'loaded-all' if @finished()
|
||||
@removeEventsFromModel(model)
|
||||
|
||||
removeEventsFromModel: (model) ->
|
||||
model.off 'sync', @modelLoaded, @
|
||||
model.off 'error', @modelErrored, @
|
||||
|
||||
getModel: (ModelClass_or_url, id) ->
|
||||
return @getModelByURL(ModelClass_or_url) if _.isString(ModelClass_or_url)
|
||||
|
|
Loading…
Reference in a new issue