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

fix(web): replaced JSON comparisons with ID comparisons in viewer #839

Merged
merged 1 commit into from
May 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/web/src/ui/views/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ const viewer = (state, i18n) => {
const theme = state.themes.themeSettings.viewer
const color = theme.rendering.meshColor
const sameColor = prevColor === color
// FIXME inefficient, replace
const sameSolids = solids.length === prevSolids.length && JSON.stringify(solids) === JSON.stringify(prevSolids)
const sameSolids = compareSolids(solids, prevSolids)
if (!(sameSolids && sameColor)) {
prevEntities = entitiesFromSolids({ color }, solids)
prevColor = color
Expand Down Expand Up @@ -229,4 +228,17 @@ const resize = (viewerElement) => {
}
}

let idCounter = Date.now()
const compareSolids = (current, previous) => {
// add an id to each solid if not already
current = current.map((s) => {
if (!s.id) s.id = ++idCounter
return s
})
// check if the solids are the same
if (!previous) return false
if (current.length !== previous.length) return false
return current.reduce((acc, id, i) => acc && current[i].id === previous[i].id, true)
}

module.exports = viewer