mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-29 06:07:32 +00:00
almost working, but not double event-listeners and not propagating to
other browsers. need more than just override model._commit
This commit is contained in:
parent
ecaf8643a4
commit
cb85c67623
3 changed files with 18 additions and 14 deletions
|
|
@ -6,7 +6,7 @@
|
|||
"dependencies": {
|
||||
"derby": "git://github.com/codeparty/derby#master",
|
||||
"racer": "git://github.com/lefnire/racer#master",
|
||||
"racer-db-mongo": "git://github.com/codeparty/racer-db-mongo#master",
|
||||
"racer-db-mongo": "git://github.com/lefnire/racer-db-mongo#mongo-update",
|
||||
"derby-ui-boot": "git://github.com/codeparty/derby-ui-boot#master",
|
||||
"derby-auth": "git://github.com/lefnire/derby-auth#master",
|
||||
"connect-mongo": "0.2.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
content = require './content'
|
||||
moment = require 'moment'
|
||||
_ = require 'underscore'
|
||||
lodash = require 'lodash'
|
||||
derby = require 'derby'
|
||||
|
||||
module.exports.newUserObject = ->
|
||||
|
|
@ -65,22 +66,17 @@ module.exports.BatchUpdate = BatchUpdate = (model) ->
|
|||
userObj = undefined
|
||||
updates = {}
|
||||
{
|
||||
queue: (path, val) ->
|
||||
commit = model._commit
|
||||
model._commit = (txn) ->
|
||||
txn.isPrivate = true
|
||||
commit.apply(this, arguments)
|
||||
user.set(path, val)
|
||||
model._commit = commit
|
||||
updates[path] = val
|
||||
queue: (path, val) -> updates[path] = val
|
||||
|
||||
getUser: -> userObj ?= user.get()
|
||||
getUser: ->
|
||||
userObj ?= lodash.cloneDeep(user.get()) # whaaa??? modifying userObj modifies the value of user.get() at that path?
|
||||
|
||||
###
|
||||
Handles updating the user model. If this is an en-mass operation (eg, server cron), pass the user object as {update}.
|
||||
otherwise, null means commit the changes immediately
|
||||
###
|
||||
updateAndQueue: (path, val) ->
|
||||
@queue path, val
|
||||
# Special function for setting object properties by string dot-notation. See http://stackoverflow.com/a/6394168/362790
|
||||
arr = path.split('.')
|
||||
arr.reduce (curr, next, index) ->
|
||||
|
|
@ -88,8 +84,15 @@ module.exports.BatchUpdate = BatchUpdate = (model) ->
|
|||
curr[next] = val
|
||||
curr[next]
|
||||
, @getUser()
|
||||
@queue path, val
|
||||
|
||||
commit: ->
|
||||
commit = model._commit
|
||||
model._commit = (txn) ->
|
||||
txn.isPrivate = true
|
||||
commit.apply(model, arguments)
|
||||
_.each updates, (val, path) ->
|
||||
if path == 'stats.hp' then debugger
|
||||
user.set(path, val)
|
||||
model._commit = commit
|
||||
user.set "update__", updates # some hackery in our own branched racer-db-mongo, see findAndModify
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,6 @@ score = (taskId, direction, times, batch) ->
|
|||
times ?= 1
|
||||
|
||||
commit = !batch?
|
||||
console.log {commit:commit}
|
||||
batch ?= new schema.BatchUpdate(model)
|
||||
userObj = batch.getUser()
|
||||
|
||||
|
|
@ -135,9 +134,11 @@ score = (taskId, direction, times, batch) ->
|
|||
adjustvalue = if (taskObj.up==false or taskObj.down==false) then false else true
|
||||
calculateDelta(adjustvalue)
|
||||
# Add habit value to habit-history (if different)
|
||||
historyEntry = { date: +new Date(), value: value } if taskObj.value != value
|
||||
historyEntry = { date: +new Date, value: value }
|
||||
if (delta > 0) then addPoints() else subtractPoints()
|
||||
model.push "_user.#{taskPath}.history", historyEntry
|
||||
taskObj.history ?= []
|
||||
taskObj.history.push historyEntry
|
||||
batch.updateAndQueue "#{taskPath}.history", taskObj.history if taskObj.value != value
|
||||
|
||||
when 'daily'
|
||||
calculateDelta()
|
||||
|
|
|
|||
Loading…
Reference in a new issue