Giter Club home page Giter Club logo

Comments (5)

ashfurrow avatar ashfurrow commented on July 24, 2024

Hey there! Any update on this? Is it an idea you think is worth pursuing?

from interstellar.

JensRavens avatar JensRavens commented on July 24, 2024

That sounds like a good idea.

But here's another solution for your problem:

class CellHolder {
  weak cell: UITableViewCell
  func doStuffOnCell(value: T) {}
}

class Cell: UITableViewCell {
  var holder: CellHolder?

  func setupCell(observable) {
    observable.subscribe {[weak holder] t: T in
      holder?.doStuffOnCell(t)
    }
  }

  override func prepareForReuse() {
    holder = nil
  }
}

This saves you from the hassle of constantly subscribing/unsubscribing during prepareForReuse and let ARC handle the task for you.

Only drawback: After the cell is dealloced the subscription stays around. I haven't done any performance testing on that yet but I assume it's more performant on the long term.

from interstellar.

ashfurrow avatar ashfurrow commented on July 24, 2024

Yeah, that's makes sense. In our case, we're going to have a few hundred observables each subscribed to hundreds and hundreds of times, in an app that needs to be remain usable during hours of use (edge case, but it's important). Usually I've followed this example, but in a few instances, I need to unsubscribe from popular observables.

I'll send a PR with a sample implementation, I'd love to get your feedback.

from interstellar.

JensRavens avatar JensRavens commented on July 24, 2024

Thank you! (I'm a quite busy until next Wednesday, so responses might take a bit)

from interstellar.

JensRavens avatar JensRavens commented on July 24, 2024

Unsubscribe has now landed in V2, therefore closing this issue.

from interstellar.

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.