MCPcopy Create free account
hub / github.com/codecombat/codecombat / saveKeyValueDb

Method saveKeyValueDb

app/models/LevelSession.js:168–187  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

166 }
167
168 saveKeyValueDb () {
169 let left
170 const keyValueDb = (left = this.get('keyValueDb')) != null ? left : {}
171 if (!this.originalKeyValueDb) { return }
172 if (this.isFake()) { return }
173 for (const key in keyValueDb) {
174 const value = keyValueDb[key]
175 const oldValue = this.originalKeyValueDb[key]
176 if (value === oldValue) { continue }
177 if ((oldValue == null) || (typeof (oldValue) === 'string') || (typeof (value) === 'string')) {
178 api.levelSessions.setKeyValue({ sessionID: this.id, key, value })
179 } else if ((typeof (oldValue) === 'number') && (typeof (value) === 'number')) {
180 const increment = value - oldValue
181 api.levelSessions.incrementKeyValue({ sessionID: this.id, key, value: increment })
182 }
183 }
184
185 if (_.size(keyValueDb)) { this.set('keyValueDb', keyValueDb) }
186 return delete this.originalKeyValueDb
187 }
188
189 countOriginalLinesOfCode (level) {
190 // Count non-whitespace, non-comment lines starting at first unique code line

Callers 2

updateKeyValueDbMethod · 0.80

Calls 3

isFakeMethod · 0.95
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected