Code Monkey home page Code Monkey logo

Comments (19)

headzoo avatar headzoo commented on August 24, 2024 1

There's no procedure in place at the moment. Unless @lxt2 has some other idea, I would think we should tag v1.0.1 and then merge your changes.

from surf.

jtwatson avatar jtwatson commented on August 24, 2024 1

This should work:

b := surf.NewBrowser()
b.HistoryJar().SetMax(1)

from surf.

jtwatson avatar jtwatson commented on August 24, 2024 1

The PR was merged into the master branch, but has not been released with a version tag...

Checkout master and you should be seeing the new Methods.

from surf.

lxt2 avatar lxt2 commented on August 24, 2024

Do you actually need the History tracked for that? I'd probably offer a NoopHistory implementation that just dropped history. I don't use the History stuff either.

from surf.

jtwatson avatar jtwatson commented on August 24, 2024

Yes, I guess that would be another way to approach this. In my situation I use Bookmarks but I never go back into History ether. But if you need history, and it grows too big, then you are in a bad place again.

I used the std lib container/list which is a doubly linked list. In my code I set the max to 10 or so and allow it to flow through the list. Not a lot of overhead to manage the pointers in the list and it keeps the History option open.

from surf.

headzoo avatar headzoo commented on August 24, 2024

Having a Browser.Close() method which frees resources sounds like a good idea.

from surf.

jtwatson avatar jtwatson commented on August 24, 2024

If you called Browser.Close(), would you expect to be able to use it again?

With the current code, simply allowing the Browser object to go out of scope effectively releases all resources to the GC to cleanup.

My issue came in when I was needing to use the Browser over many requests. So I added a method Browser.ClearHistory() to explicitly clear history at a given point. I also added a Browser.SetMaxHistory(max int) to limit history growth to a number of items. I left the default at unlimited as to not change the exiting behavior and possibly cause a BC issue, but it might be okay to have a sensible default here of 100 items or something like that.

from surf.

headzoo avatar headzoo commented on August 24, 2024

The two methods to clear and limit the history sound good to me too, though I would probably put those methods on the jar.History interface. (In which case they would be named Clear() and SetMax().)

from surf.

jtwatson avatar jtwatson commented on August 24, 2024

Those two methods do exist on jar.History, but the current Browser does not provide access to Browser.history. So you would have to do something like this:

b := surf.NewBrowser()
hist := jar.NewMemoryHistory()
hist.Max(100)
b.SetHistoryJar(hist)

Because this felt to painful, I added the corresponding methods to the Browser.

b := surf.NewBrowser()
b.SetMaxHistory(100)

Maybe it would just be better to make the History object accessible.

from surf.

headzoo avatar headzoo commented on August 24, 2024

Maybe it would just be better to make the History object accessible.

I think that approach would work best, and if we're doing that, we should make the other jar objects accessible as well.

from surf.

jtwatson avatar jtwatson commented on August 24, 2024

Okay. I will work on that.

from surf.

jtwatson avatar jtwatson commented on August 24, 2024

I removed the methods browser.SetMaxHistory() and browser.ClearHistory(). I also exposed 4 jar objects so they can be manipulated directly.

from surf.

headzoo avatar headzoo commented on August 24, 2024

Looks good, though the Browsable interface is missing the getter methods. Thanks for your effort in making these changes!

from surf.

jtwatson avatar jtwatson commented on August 24, 2024

Done. We now have the same methods as part of the Browsable interface.

from surf.

jtwatson avatar jtwatson commented on August 24, 2024

The last item that I would like to do is change the default history length to 100. What is the procedure to make this in a patch release?

from surf.

lxt2 avatar lxt2 commented on August 24, 2024

Is there a PR for this that I've missed?

from surf.

jtwatson avatar jtwatson commented on August 24, 2024

I just added a PR to change the default.

from surf.

MikhailKlemin avatar MikhailKlemin commented on August 24, 2024

I do not understand now... how would you limit history to 1 page now?

from surf.

MikhailKlemin avatar MikhailKlemin commented on August 24, 2024

This should work:

b := surf.NewBrowser()
b.HistoryJar().SetMax(1)

There no HistoryJar() method

from surf.

Related Issues (20)

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.