cloudwu / tracedoc

33 stars 19 forks source link

tracedoc.lua 107行是否有问题 #1

Open wushi333333 opened 7 years ago

wushi333333 commented 7 years ago

tracedoc.lua 107行,似乎不正确 for k in pairs(lv) do keys[k] = true end 大神,这个东西是否应该改成这样 for k in pairs(lv._lastversion) do keys[k] = true end

cloudwu commented 7 years ago

bug 的话,给个 testcase ?

cloudwu commented 7 years ago

如果你觉得你的改法有道理,那么一定能制造一个 testcase 在原版本中是错的,改后是对的。

这可以节省所有人的时间。

wushi333333 commented 7 years ago

local tracedoc = require "app.tracedoc"

local doc = tracedoc.new { a = 1, b = { 1,2,3 }, c = { d = 4 , e = 5 }, d = {}, }

local function dump1(doc) local changes = tracedoc.commit(doc, {}) print("Dump:") for k,v in pairs(doc) do print(k,v) if type(v) == "table" then for k, v in pairs(v) do print("\t",k,v) end end end print("changes:") for k,v in pairs(changes) do print(k,v) end end

dump1(doc)

dump(doc,"doc",100) print "-----------------------------"

doc.b[3] = nil doc.b = { 1,3 } -- remove [3], change [2] dump(doc,"doc222",100)

-- 结果是 b直接被清空了 -- "doc" = { -- "_changes" = { -- "_doc" = REF -- "_keys" = { -- } -- } -- "_dirty" = false -- "_lastversion" = { -- "a" = 1 -- "b" = { -- "_changes" = { -- "_doc" = REF -- "_keys" = { -- } -- } -- "_dirty" = false -- "_lastversion" = { -- 1 = 1 -- 2 = 2 -- 3 = 3 -- } -- "_parent" = REF -- } -- "c" = { -- "_changes" = { -- "_doc" = REF -- "_keys" = { -- } -- } -- "_dirty" = false -- "_lastversion" = { -- "d" = 4 -- "e" = 5 -- } -- "_parent" = REF -- } -- "d" = { -- "_changes" = { -- "_doc" = REF -- "_keys" = { -- } -- } -- "_dirty" = false -- "_lastversion" = { -- } -- "_parent" = REF -- } -- } -- "_parent" = false -- }


-- "doc222" = { -- "_changes" = { -- "_doc" = REF -- "_keys" = { -- } -- } -- "_dirty" = true -- "_lastversion" = { -- "a" = 1 -- "b" = { -- } -- "c" = { -- "_changes" = { -- "_doc" = REF -- "_keys" = { -- } -- } -- "_dirty" = false -- "_lastversion" = { -- "d" = 4 -- "e" = 5 -- } -- "_parent" = REF -- } -- "d" = { -- "_changes" = { -- "_doc" = REF -- "_keys" = { -- } -- } -- "_dirty" = false -- "_lastversion" = { -- } -- "_parent" = REF -- } -- } -- "_parent" = false -- }