mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -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
|
@mustPopulate = model
|
||||||
model.saveBackups = @shouldSaveBackups(model)
|
model.saveBackups = @shouldSaveBackups(model)
|
||||||
model.fetch() unless model.loaded or model.loading
|
model.fetch() unless model.loaded or model.loading
|
||||||
model.on('sync', @modelLoaded) unless model.loaded
|
model.on('sync', @modelLoaded, @) unless model.loaded
|
||||||
model.once('error', @modelErrored) unless model.loaded
|
model.once('error', @modelErrored, @) unless model.loaded
|
||||||
url = model.url()
|
url = model.url()
|
||||||
@models[url] = model unless @models[url]?
|
@models[url] = model unless @models[url]?
|
||||||
@modelLoaded(model) if model.loaded
|
@modelLoaded(model) if model.loaded
|
||||||
|
@ -18,12 +18,13 @@ class SuperModel
|
||||||
shouldPopulate: (url) -> return true
|
shouldPopulate: (url) -> return true
|
||||||
shouldSaveBackups: (model) -> return false
|
shouldSaveBackups: (model) -> return false
|
||||||
|
|
||||||
modelErrored: (model) =>
|
modelErrored: (model) ->
|
||||||
@trigger 'error'
|
@trigger 'error'
|
||||||
|
@removeEventsFromModel(model)
|
||||||
|
|
||||||
modelLoaded: (model) =>
|
modelLoaded: (model) ->
|
||||||
schema = model.schema()
|
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 = model.getReferencedModels(model.attributes, schema.attributes)
|
||||||
refs = [] unless @mustPopulate is model or @shouldPopulate(model)
|
refs = [] unless @mustPopulate is model or @shouldPopulate(model)
|
||||||
# console.log 'Loaded', model.get('name')
|
# console.log 'Loaded', model.get('name')
|
||||||
|
@ -33,10 +34,15 @@ class SuperModel
|
||||||
continue if @models[refURL]
|
continue if @models[refURL]
|
||||||
@models[refURL] = ref
|
@models[refURL] = ref
|
||||||
ref.fetch()
|
ref.fetch()
|
||||||
ref.on 'sync', @modelLoaded
|
ref.on 'sync', @modelLoaded, @
|
||||||
|
|
||||||
@trigger 'loaded-one', model: model
|
@trigger 'loaded-one', model: model
|
||||||
@trigger 'loaded-all' if @finished()
|
@trigger 'loaded-all' if @finished()
|
||||||
|
@removeEventsFromModel(model)
|
||||||
|
|
||||||
|
removeEventsFromModel: (model) ->
|
||||||
|
model.off 'sync', @modelLoaded, @
|
||||||
|
model.off 'error', @modelErrored, @
|
||||||
|
|
||||||
getModel: (ModelClass_or_url, id) ->
|
getModel: (ModelClass_or_url, id) ->
|
||||||
return @getModelByURL(ModelClass_or_url) if _.isString(ModelClass_or_url)
|
return @getModelByURL(ModelClass_or_url) if _.isString(ModelClass_or_url)
|
||||||
|
|
Loading…
Reference in a new issue