Giter VIP home page Giter VIP logo

Comments (9)

GuidoPreite avatar GuidoPreite commented on June 3, 2024 1

a setInterval every X seconds should do the trick, but you are right, I have no idea performance-wise how this works. I can eventually create a 3 state dropdown (like: off, autosave, manual save) so a user can decide the behavior, default would be off and if a user wants to enable the functionality is free to do so

from drb.

yagasoft avatar yagasoft commented on June 3, 2024 1

Great idea.

One final suggestion: please consider using setTimeout instead of setInterval. That is because if, for example, the interval is 5 seconds, and the save function takes 3 seconds, then the user is left with 2 seconds of 'unfrozen' UI to do any work. If the save function takes the full 5 seconds, then the UI will hang.

You can scale that up to any interval for the same outcome. setTimeout allows for a breather on the UI for slow logic.

Regardless of the method, thank you for listening.

from drb.

GuidoPreite avatar GuidoPreite commented on June 3, 2024 1

@yagasoft I had another change in the pipeline so I had time to check about this functionality.
I released a new version (1.0.0.14), now you can manually save the collection to localStorage using the Save State option (right click on the collection).
The localStorage key name includes the instance url, so if you use the same browser with different instances it should work.
I know it's not the autosave functionality but I will keep this issue open for a while as reminder, I want to do some tests with the Worker API but right now I can't dedicate too much time on this, the manual save was easier to implement.

from drb.

yagasoft avatar yagasoft commented on June 3, 2024

Please let me know if you would like me to take a stab at it.

from drb.

GuidoPreite avatar GuidoPreite commented on June 3, 2024

@yagasoft I am not familiar with the functionality, probably I can replicate the behavior you described using the localStorage (so the current state is always saved there and when the page is loaded it checks if an entry exists there).
If you have suggestions on how this can be added to DRB let me know

from drb.

yagasoft avatar yagasoft commented on June 3, 2024

@GuidoPreite
Indeed, that is what I had in mind exactly.

Periodically, say every 5 seconds, invoke the 'save' functionality but don't pop up the 'save file' dialogue. Instead, save the JSON directly to localStorage.

On load, check the localStorage for the JSON. If found, invoke the 'load' function but don't pop up the 'load file' dialogue. Instead, load the JSON read from storage.

I am not sure how performant is the 'save' function, but if it's too slow with large collections, we could replace the internal loop with an always-visible button to save progress in the browser. Or, we could measure the performance of the save, and if it takes longer than 100ms, for example, we could show that button for the user and increase the loop time to be 60 seconds, for example.

I am just spitballing, to be honest, but there are a lot of ways to do it.

Shame that JS is single-threaded, or it would have been straightforward. One way to overcome the performance hit of the internal loop is to implement a Web Worker ...
https://medium.com/techtrument/multithreading-javascript-46156179cf9a

from drb.

yagasoft avatar yagasoft commented on June 3, 2024

Manual save in the browser will make things much easier. Extra functionality than that is nice to have for sure.
Thank you.

from drb.

GuidoPreite avatar GuidoPreite commented on June 3, 2024

@yagasoft thanks again for making this suggestion. It was very helpful for me to be able to save the collection state inside localStorage when I added the Fetch API syntax and when I added the REST Client export.
I thought in the last days about the autosave and I decided to don't proceed as I can't create something reliable and suitable for everybody.
I also checked the jsTree events (the request configuration is saved inside the data attribute of the jsTree node) but also the "changed" one doesn't get triggered when the data attribute is updated.
Sadly I also update the configuration (DRB.Metadata.CurrentNode that is a reference to the jsTree node) not uniformly in the code I wrote, making it difficult to pursue an approach related to this.
Feel free to comment if you want to add something, I will close this ticket 3 days later.

from drb.

yagasoft avatar yagasoft commented on June 3, 2024

Thank you for considering my suggestion.

You could create a loop in a Web Worker and let it save periodically, regardless of events. The saved data would be exactly the same as the 'export to JSON' functionality. It wouldn't affect performance. However, you know your solution better than I do.

In any case, thanks again for adding the current save functionality. It's very helpful, indeed.

from drb.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.