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

View.update() is called for each individual Raster imported using importJSON() #830

Closed
nicholaswmin opened this issue Nov 14, 2015 · 2 comments

Comments

@nicholaswmin
Copy link

Test case

  • With 10 Rasters on a project, call exportJSON()
  • project.clear(), the project
  • Reimport the exported json with the 10 Rasters.
Expected Result
  • View.update() (redraw cycle) is called once when it has imported/processed all 10 Rasters
Actual Result
  • View.update() (redraw cycle) is called 10 times(for each Raster) during the importJSON() "process".
Device/Browser
  • Evergreen browsers

So, here's a demonstrable example on Codepen, where the console logs that view.update() is called 10 times when importing a 10 Raster json.

Working with paper-full.js,

  • I've put a console.log() in View.update() in paper-full.
  • I create a project with 10 Rasters, export it with exportJSON() and then reimport it with importJSON().
  • view.update() is logged in the console 10 times (was called 10 times).
  • calls to view.update() seem to be coming from Raster's setSource() in line 4844.

Why does the redraw cycle kick-in for each Raster when importing? I'm posting this cause it's a bit of an expensive operation when shuffling Raster json's around and it decimates the experience. Is it really necessary?

Plus this happens only when importing json's with Rasters.
When project has 10 Path items it is improrted with view.update() being called just once when it's done, just as expected.

@lehni
Copy link
Member

lehni commented Nov 17, 2015

This is the origin of these additional calls: https://github.com/paperjs/paper.js/blob/develop/src/item/Raster.js#L341

I need to find a way to know when these updates are desired and when not... #827 is a related issue also, since all images being loaded should trigger the load event of the SVG import call... It's complicated!

@nicholaswmin
Copy link
Author

I've temporarily solved it by using a debouncer() to collapse all those calls into a single one. Bit of a crude workaround but for now it patches things up.

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

2 participants