Improve perf. of mod version parsing

Add a SimpleStack model which is identical to the regular Stack model
except for not being a Backbone.Model subclass.  Since so many stacks
are created during mod version parsing, this makes about a 50%
difference in performance during loading.
This commit is contained in:
Andrew Miner
2015-03-01 12:08:04 -08:00
parent d530ff73a3
commit 6c40711f73
2 changed files with 23 additions and 1 deletions
@@ -10,7 +10,7 @@ Item = require '../item'
ItemSlug = require '../item_slug' ItemSlug = require '../item_slug'
ModVersion = require '../mod_version' ModVersion = require '../mod_version'
Recipe = require '../recipe' Recipe = require '../recipe'
Stack = require '../stack' Stack = require '../simple_stack'
StringBuilder = require '../string_builder' StringBuilder = require '../string_builder'
######################################################################################################################## ########################################################################################################################
+22
View File
@@ -0,0 +1,22 @@
###
Crafting Guide - simple_stack.coffee
Copyright (c) 2014-2015 by Redwood Labs
All rights reserved.
###
########################################################################################################################
module.exports = class Stack
constructor: (attributes={}, options={})->
if not attributes.itemSlug? then throw new Error 'attributes.itemSlug is required'
attributes.quantity ?= 1
@itemSlug = attributes.itemSlug
@quantity = attributes.quantity
# Object Overrides #############################################################################
toString: ->
return "#{@quantity} #{@itemSlug}"