Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes 的 diff 机制 #37

Open
Brooooooklyn opened this issue Feb 3, 2017 · 4 comments
Open

changes 的 diff 机制 #37

Brooooooklyn opened this issue Feb 3, 2017 · 4 comments

Comments

@Brooooooklyn
Copy link
Contributor

Lovefield 的 observe 在 diff change 时是 shallow equal (和 React 一样)

Note that observing a query with columns of lf.Type.OBJECT or lf.Type.ARRAY_BUFFER will trigger observers ONLY IF the reference to those objects changed (assuming no other column changed). If the lf.Type.OBJECT object was updated in place, observers will not be triggered, since Lovefield does not know the structure of such objects to compare before and after (and doing so would hurt performance).

google/lovefield@4fb1916#diff-1986b255fba1a14a3b09577a2fed28caR643

@Saviio
Copy link
Collaborator

Saviio commented Feb 3, 2017

对复杂类型lf肯定会用浅比较的,因为做深比较的话开销太大了,划不来

@Brooooooklyn
Copy link
Contributor Author

所以我们用的时候像 inbolveMembers 这种数组就要注意不能复用对象了,不然要踩坑

@chuan6
Copy link
Contributor

chuan6 commented Feb 3, 2017

这种场合下也许可以用 immutable.js 里的数据结构实现引用与值的对应,让等值比较高效准确,同时又保证在数据结构上做的“更新”,即:产生新的值,在底层有比较高效的实现。(就如这里提到的,利用 clojurescript 自带的 immutable 数据结构来把 shouldComponentUpdate 里的 diff 逻辑用简单的引用比较代替)

@Saviio
Copy link
Collaborator

Saviio commented Feb 3, 2017

@chuan6 immutable.js 也会踩坑...,但引入immutable.js有个问题,就是:它不是一个 透明的库,它引入了一个强约束即:整套开发链路上都必须理解immutable.js,知晓它规避了什么样的问题。

const usr= await sdk.getUser().values()
/*
usr = {
   name: 'bar',
   involveMembers: immutableArray,
   // original
   involveMembers: [
      'foo',
      'baz'
   ]
}
*/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants