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

exchange position but result asymmetry! #11

Open
ascoders opened this issue Jun 26, 2016 · 5 comments
Open

exchange position but result asymmetry! #11

ascoders opened this issue Jun 26, 2016 · 5 comments

Comments

@ascoders
Copy link

Occurs when complex objects

json1:

{"component":"gaea-layout","props":{"name":"外壳","options":{"width":{"value":"100%","editable":false},"flexGrow":{"value":1,"editable":false},"flexDirection":{"value":"column"}}},"childs":[{"component":"gaea-layout","childs":[{"component":"title","props":{"options":{"text":{"value":"Gaea"}}}}],"props":{"options":{"alignItems":{"value":"stretch"},"flexDirection":{"value":"column"}}}},{"component":"gaea-layout","childs":[{"component":"gaea-layout","props":{"options":{"width":{"value":"50%"},"alignItems":{"value":"center"},"justifyContent":{"value":"center"},"minHeight":{"value":50}}}},{"component":"gaea-layout","props":{"options":{"width":{"value":"50%"},"alignItems":{"value":"center"},"justifyContent":{"value":"center"},"minHeight":{"value":50}}},"childs":[{"component":"gaea-paragraph","props":{"options":{"text":{"value":"支持自由定制组件+细粒度通用组件"},"fontSize":{"value":16}}}}]}],"props":{"options":{"minHeight":{"value":50}}}},{"component":"gaea-paragraph","props":{"options":{"text":{"value":"无限层级嵌套+任意组合"},"fontSize":{"value":16}}}}]}

json2:

{"component":"gaea-layout","props":{"name":"外壳","options":{"width":{"value":"100%","editable":false},"flexGrow":{"value":1,"editable":false},"flexDirection":{"value":"column"}}},"childs":[{"component":"gaea-layout","childs":[{"component":"title","props":{"options":{"text":{"value":"Gaea"}}}}],"props":{"options":{"alignItems":{"value":"stretch"},"flexDirection":{"value":"column"}}}},{"component":"gaea-layout","childs":[{"component":"gaea-layout","props":{"options":{"width":{"value":"50%"},"alignItems":{"value":"center"},"justifyContent":{"value":"center"},"minHeight":{"value":50}}},"childs":[{"component":"gaea-paragraph","props":{"options":{"text":{"value":"无限层级嵌套+任意组合"},"fontSize":{"value":16}}}}]},{"component":"gaea-layout","props":{"options":{"width":{"value":"50%"},"alignItems":{"value":"center"},"justifyContent":{"value":"center"},"minHeight":{"value":50}}},"childs":[{"component":"gaea-paragraph","props":{"options":{"text":{"value":"支持自由定制组件+细粒度通用组件"},"fontSize":{"value":16}}}}]}],"props":{"options":{"minHeight":{"value":50}}}}]}

and run:

var test1 = require('./test1.json')
var test2 = require('./test2.json')
var map1 = Immutable.fromJS(test1)
var map2 = Immutable.fromJS(test2)

console.log(diff(map1, map2).toJS())
console.log(diff(map2, map1).toJS())

here is the result:

bug

The second is correct

@ascoders
Copy link
Author

ascoders commented Jul 1, 2016

any one help?

@pedroteixeira
Copy link
Contributor

Hi ascoders, the diff function is not a symetrical operation, the produced patch operations are relative to the first object. If you could create a test case, I'll have a look into the issue.
best regards!

@ascoders
Copy link
Author

ascoders commented Jul 2, 2016

hi pedroteixeira, thanks for your help, here is the test case:

git clone https://github.com/ascoders/immutable-js-diff-test-case.git
cd immutable-js-diff-test-case
npm install
node index.js

and you will see this:

image

the second output is correct, i think the first output should like this:

[ { op: 'remove',
path: '/childs/2',
value: { component: 'gaea-paragraph', props: [Object] } } ,
{ op: 'add', path: '/childs/1/childs/0/childs' },]

@ascoders
Copy link
Author

hello

@ascoders
Copy link
Author

ascoders commented Aug 4, 2016

@pedroteixeira ^^

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

No branches or pull requests

2 participants