Massive refactoring to clean up models

* Tweak style of quantity label in output box to be more visible
* Move data files for all mods under a directory for the specific
  version of the mod
* Add a `silent` property to the base model to prevent models which
  shouldn't be observed from emitting events
* Change the term "itemSlug" to just "slug" across the board
* Change all models so that they don't require their parent in their
  constructors and so that they don't automatically add themselves to
  their parents lists
* Remove a bunch of unnecessary event triggering
* Tighten up access to various lists of children across all models
* Refactor the guts of the V2 parser into an abstract base class so
  it can be used for other parsers in the future
* Remove a number of unused methods
This commit is contained in:
Andrew Miner
2015-01-17 11:49:07 -08:00
parent bb959264ee
commit 83868e2760
34 changed files with 530 additions and 519 deletions
+5 -3
View File
@@ -13,7 +13,7 @@ All rights reserved.
module.exports = class BaseModel extends Backbone.Model
constructor: (attributes={}, options={})->
options.allowedSyncMethods = []
options.silent ?= true
super attributes, options
makeGetter = (name)-> return -> @get name
@@ -22,9 +22,9 @@ module.exports = class BaseModel extends Backbone.Model
continue if name is 'id'
Object.defineProperty this, name, get:makeGetter(name), set:makeSetter(name)
@allowedSyncMethods = options.allowedSyncMethods
@silent = options.silent
@state = ModelState.unloaded
@state = ModelState.unloaded
@on 'request', => @state = ModelState.loading
@on 'sync', => @state = ModelState.loaded
@on 'error', => @state = ModelState.error
@@ -61,6 +61,7 @@ module.exports = class BaseModel extends Backbone.Model
success: (text, status, xhr)=> resolve @onLoadSucceeded text, status, xhr
error: (xhr, status, error)=> reject @onLoadFailed error, status, xhr
@loading.catch -> # do nothing. prevents unhandled promise warnings
return @loading
parse: (text)->
@@ -70,6 +71,7 @@ module.exports = class BaseModel extends Backbone.Model
throw new Error "#{@constructor.name} (#{@cid}) is not permitted to #{method}"
trigger: (name)->
return if @silent
logger.trace "#{@constructor.name}.#{@cid} triggered a \"#{name}\" event"
super