Add system names into delta messages

This commit is contained in:
dpen2000 2014-04-18 16:02:14 -04:00
parent b20f8fd260
commit 75b759b1dc
3 changed files with 15 additions and 2 deletions

View file

@ -0,0 +1,10 @@
CocoClass = require 'lib/CocoClass'
namesCache = {}
class SystemNameLoader extends CocoClass
getName: (id) -> namesCache[id]?.name
setName: (system) -> namesCache[system.get('original')] = {name:system.get('name')}
module.exports = new SystemNameLoader()

View file

@ -1,3 +1,4 @@
SystemNameLoader = require 'lib/SystemNameLoader'
###
Good-to-knows:
dataPath: an array of keys that walks you up a JSON object that's being patched
@ -73,7 +74,7 @@ expandFlattenedDelta = (delta, left, schema) ->
humanKey = null
childData = if i is delta.dataPath.length-1 and delta.action is 'added' then o[0] else childLeft
humanKey ?= childData.name or childData.id if childData
humanKey ?= "#{childSchema.title} ##{key+1}" if childSchema.title and _.isNumber(key)
humanKey ?= SystemNameLoader.getName(childData?.original)
humanKey ?= "#{childSchema.title}" if childSchema.title
humanKey ?= _.string.titleize key
humanPath.push humanKey
@ -155,4 +156,4 @@ prunePath = (delta, path) ->
else
prunePath delta[path[0]], path.slice(1)
keys = (k for k in _.keys(delta[path[0]]) when k isnt '_t')
delete delta[path[0]] if keys.length is 0
delete delta[path[0]] if keys.length is 0

View file

@ -1,4 +1,5 @@
CocoModel = require('./CocoModel')
SystemNameLoader = require('lib/SystemNameLoader')
module.exports = class LevelSystem extends CocoModel
@className: "LevelSystem"
@ -16,6 +17,7 @@ module.exports = class LevelSystem extends CocoModel
onLoaded: ->
super()
@set 'js', @compile(@get 'code') unless @get 'js'
SystemNameLoader.setName @
compile: (code) ->
if @get('language') and @get('language') isnt 'coffeescript'